-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuthNavigation.js
34 lines (26 loc) · 1.16 KB
/
AuthNavigation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React, { useState, useEffect } from 'react';
import { SignedInStack, SignedOutStack } from './screens/Navigation.js';
import { firebase } from './firebase.js';
import LogoScreen from './screens/LogoScreen.js';
const AuthNavigation = () => {
const [currentUser, setCurrentUser] = useState(null);
async function resumeSession(){
await firebase.auth().onAuthStateChanged((user) => user ? setCurrentUser(user) : setCurrentUser(null));
}
useEffect(()=>{
resumeSession()
}, [])
// useEffect(
// () => firebase.auth().onAuthStateChanged((user) => {
// user ? setCurrentUser(user) : setCurrentUser(null)
// // If the auth instance returns a user, setCurrentUser(User)
// // else (means the auth returns null) setCurrentUser(null)
// // Side Note: Once the user logs in (ex: firebase.auth().signInWithEmailAndPassword(email, password) (line 15 in LoginForm.js)),
// // that user becomes the current user of the Auth instance. So untill that user logs out (ex: ) that user
// // will keep on being the user of the Auth instance
// }),
// []
// )
return <>{currentUser ? <SignedInStack /> : <SignedOutStack />}</>
}
export default AuthNavigation