-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticator.tsx
45 lines (39 loc) · 1.15 KB
/
Authenticator.tsx
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
import { useContext, useEffect, useState } from 'react';
import { ActivityIndicator, View } from 'react-native';
import * as SecureStore from 'expo-secure-store';
import { AppContext } from './Providers/AppProvider';
import AuthStack from './Navigators/AuthStack';
import StackNavigator from './Navigators/StackNavigator';
const Authenticator = () => {
const { user, setUser } = useContext<any>(AppContext)
const [ loading, setLoading ] = useState<boolean>(true);
useEffect(() => {
SecureStore.getItemAsync('user')
.then(userString => {
if (userString) {
let userObject = JSON.parse(userString)
setUser(userObject);
}
setLoading(false);
})
.catch(err => {
setLoading(false);
console.log(err);
})
}, []);
console.log("userrbbbb: ", !user)
if (loading) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator size="large" color={"#064929"} />
</View>
)
} else if (!user) {
return <AuthStack />
} else {
return <StackNavigator />
}
// if(user !== null && user !== undefined) return <StackNavigator />;
// else return <AuthStack />;
}
export default Authenticator