Skip to content

Commit

Permalink
fix: authcontext reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
Srish-ty committed Mar 27, 2024
1 parent 048cb74 commit 6a88c7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
11 changes: 7 additions & 4 deletions src/components/form/FormContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { useEffect, useState, useContext } from 'react';

Check failure on line 1 in src/components/form/FormContainer.jsx

View workflow job for this annotation

GitHub Actions / eslint / Eslint Check (18)

'useContext' is defined but never used
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,
Expand Down
10 changes: 4 additions & 6 deletions src/components/shared/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useContext } from 'react';

Check failure on line 1 in src/components/shared/NavBar.jsx

View workflow job for this annotation

GitHub Actions / eslint / Eslint Check (18)

'useContext' is defined but never used
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';
Expand All @@ -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 }) {

Check failure on line 12 in src/components/shared/NavBar.jsx

View workflow job for this annotation

GitHub Actions / eslint / Eslint Check (18)

'setUserData' is defined but never used
//const { setUserData } = useContext(AuthContext);

const { navItems, logo } = Navigation;
const [isNavOpen, setIsNavOpen] = useState(false);
Expand Down Expand Up @@ -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}>
<Text variant='navButton'>Login</Text>
</Button>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/firebase/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [{}, {}];
});
};

Expand Down
7 changes: 4 additions & 3 deletions src/pages/playground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<AuthContext.Provider value={{ currentUser, userData, setUserData }}>
<div>
<NavBar />
<NavBar setUserData={setUserData} />
<div className='container py-6'>
<h1>Hero Text</h1>
<PersonalizedText>Personalized Text</PersonalizedText>
Expand Down Expand Up @@ -40,7 +41,7 @@ export default function Playground() {
</ul>
</div>

<FormContainer />
<FormContainer userValues={{ currentUser, userData }} />
<Footer />
</div>
</AuthContext.Provider>
Expand Down

0 comments on commit 6a88c7f

Please sign in to comment.