diff --git a/src/components/form/FormContainer.jsx b/src/components/form/FormContainer.jsx index 6f585df..d7badb6 100644 --- a/src/components/form/FormContainer.jsx +++ b/src/components/form/FormContainer.jsx @@ -1,15 +1,18 @@ import React, { useEffect, useState, useContext } from 'react'; -import AuthContext from '../../context/AuthContext'; +//import AuthContext from '../../context/AuthContext'; import { Heading, Paragraph } from '../shared'; import { Inputs, TextAreaInput } from '../shared/partials/FormInputs'; import formimg from '../../assets/images/form-tickets.png'; import { donation, feeCoverage, initialContent, inputContent, lastPartContent } from '../../data/formInformation'; import { storeFormData } from '../../firebase/registration'; -//import { loggedUser, logUserRegData } from '../../firebase/login'; +import { loggedUser, logUserRegData } from '../../firebase/login'; const FormContainer = () => { - const { currentUser, userData } = useContext(AuthContext); - //const userData = logUserRegData; + //const { currentUser, userData } = useContext(AuthContext); + + const currentUser = loggedUser, + userData = logUserRegData; + console.log('userData:', userData); const [isValid, setValid] = useState({ recRollNumber: false, diff --git a/src/components/shared/NavBar.jsx b/src/components/shared/NavBar.jsx index fbba0e9..27d35a1 100644 --- a/src/components/shared/NavBar.jsx +++ b/src/components/shared/NavBar.jsx @@ -1,5 +1,5 @@ import { useState, useContext } from 'react'; -import AuthContext from '../../context/AuthContext'; +//import AuthContext from '../../context/AuthContext'; import { Link } from 'react-router-dom'; import Text from './typography/Text'; import Navigation from '../../data/Navigation'; @@ -9,8 +9,8 @@ import Logo from './Logo'; import Hamburger from './Hamburger'; import { signInWithGoogle } from '../../firebase/login'; -function NavBar() { - const { setUserData } = useContext(AuthContext); +function NavBar({ setUserData }) { + //const { setUserData } = useContext(AuthContext); const { navItems, logo } = Navigation; const [isNavOpen, setIsNavOpen] = useState(false); @@ -43,9 +43,7 @@ function NavBar() { style={{ boxShadow: '2px 2px 0px 0px #000, 3px 4px 9.2px 0px rgba(222, 222, 222, 0.48) inset', }} - onClick={() => { - setUserData(signInWithGoogle); - }}> + onClick={signInWithGoogle}> Login diff --git a/src/firebase/login.js b/src/firebase/login.js index a0988fc..44dab70 100644 --- a/src/firebase/login.js +++ b/src/firebase/login.js @@ -6,24 +6,24 @@ import { app } from './firebaseConfig'; export var loggedUser = {}; // user data from Google Auth export var logUserRegData = {}; // registration data from Firestore -export const signInWithGoogle = () => { +export const signInWithGoogle = async () => { const auth = getAuth(app); const provider = new GoogleAuthProvider(); - signInWithPopup(auth, provider) + await signInWithPopup(auth, provider) .then(async result => { const user = result.user; loggedUser = { name: user.displayName, email: user.email, uid: user.uid }; - console.log('loggedUser:', loggedUser); logUserRegData = await getUserData(user.uid); - console.log('User Registration Data:', logUserRegData); - return { loggedUser, logUserRegData }; + console.log('loggedUser:', loggedUser, 'User Registration Data:', logUserRegData); + return [loggedUser, logUserRegData]; }) .catch(error => { const errorMessage = error.message; console.error(errorMessage); + return [{}, {}]; }); }; diff --git a/src/pages/playground.jsx b/src/pages/playground.jsx index 7494822..d40a58e 100644 --- a/src/pages/playground.jsx +++ b/src/pages/playground.jsx @@ -7,12 +7,13 @@ import FormContainer from '../components/form/FormContainer.jsx'; import NavBar from '../components/shared/NavBar'; export default function Playground() { - const [{ currentUser, userData }, setUserData] = useState({}); + const [[currentUser, userData], setUserData] = useState([{}, {}]); + console.log('current user', currentUser); return (
- +

Hero Text

Personalized Text @@ -40,7 +41,7 @@ export default function Playground() {
- +