diff --git a/src/components/Account.jsx b/src/components/Account.jsx
index a676efe..eaa8416 100644
--- a/src/components/Account.jsx
+++ b/src/components/Account.jsx
@@ -5,6 +5,7 @@ import {getAuth, onAuthStateChanged} from 'firebase/auth'
const Account = () => {
const [signIn, setSignIn] = useState('false')
+ const [apiKey, setApiKey] = useState('')
const auth = getAuth()
@@ -16,12 +17,75 @@ const Account = () => {
setSignIn(false)
}
})
+
+ const uploadApiKey = async (e) => {
+ e.preventDefault()
+
+ const data = await makeRequest()
+ console.log(data)
+
+ if (await validateRequest(data)) {
+
+
+ } else {
+
+
+ }
+
+ }
+
+ const makeRequest = async () => {
+ try {
+ const request = {
+ method: "GET",
+ headers: {
+ 'X-Api-Key': apiKey,
+ "content-type": "application/json"
+ }
+ }
+ const response = await fetch(`https://api.clockify.me/api/v1/workspaces/`, request)
+ const data = await response.json()
+
+ return await data
+
+ } catch (error) {
+ console.log(error)
+ }
+ }
+
+ const validateRequest = async (data) => {
+ if (data.code !== 1000) {
+ console.log('TODO BIEN')
+ return true
+ } else {
+ console.log('TODO MAL')
+ return false
+ }
+ }
return (
{
signIn ?
-
Insert your Clockify API here
:
+
+
One more step...
+ Insert your Clockify API here
+
+ :
Sign in before access to this page...
}
diff --git a/src/components/Identify.jsx b/src/components/Identify.jsx
index 7ff35ae..0603573 100644
--- a/src/components/Identify.jsx
+++ b/src/components/Identify.jsx
@@ -6,6 +6,7 @@ import {firebase} from './Firebase/firebase'
import {withRouter} from 'react-router-dom'
import {getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword} from 'firebase/auth'
+import { getFirestore, collection, doc, setDoc } from 'firebase/firestore'
const Identify = (props) => {
@@ -24,6 +25,12 @@ const Identify = (props) => {
try {
const response = await createUserWithEmailAndPassword(auth, email, password)
+ console.log(response)
+ console.log(response.user)
+
+ const uid = response.user.uid
+
+ addNewUserToFirebase(uid)
} catch (error) {
console.log(error)
@@ -32,6 +39,22 @@ const Identify = (props) => {
}
}
+ const addNewUserToFirebase = async (uid) => {
+
+ try {
+
+ const db = getFirestore(firebase)
+
+ await setDoc(doc(db, 'users', uid), {
+
+ keyClockify: ''
+ })
+
+ } catch (error) {
+ alert(error)
+ }
+ }
+
const login = async () => {
try {
@@ -39,7 +62,7 @@ const Identify = (props) => {
console.log(response)
console.log(response.user)
- props.history.push('/config-account')
+ //props.history.push('/config-account')
} catch (error) {
console.log(error)