-
Notifications
You must be signed in to change notification settings - Fork 0
/
Container.js
52 lines (44 loc) · 1.29 KB
/
Container.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, {useEffect, useState} from 'react';
import Login from './src/screens/Login';
import {auth} from './src/firebase/utils';
import store from './src/redux/store';
import {SET_USER} from './src/redux/types';
import MainNavigator from './src/navigation/MainNavigator';
const Container = () => {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Handle user state changes
const onAuthStateChanged = (user) => {
setUser(user);
if (user) {
// console.log('user from container', user);
store.dispatch({
type: SET_USER,
payload: {
authenticated: true,
userName: user.displayName,
userImage: user.photoURL,
userId: user.uid,
},
});
}
if (initializing) setInitializing(false);
};
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber;
}, []);
// const renderScreen = auth.authenticated ? <MainNavigator /> : <Login />;
if (initializing) return null;
if (!user) {
return <Login />;
}
return <MainNavigator />;
};
// const mapStateToProps = (state) => {
// return {
// auth: state.auth,
// };
// };
export default Container;