-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
76 lines (65 loc) · 1.63 KB
/
App.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'react-native-gesture-handler';
import { StatusBar } from 'expo-status-bar';
import React, {useState} from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './src/hooks/useCachedResources';
import useColorScheme from './src/hooks/useColorScheme';
import Navigation from './src/navigation';
import UserContext from './src/Context';
//import {setJwt, getJwt} from './src/services/auth/JwtService';
const App = (props: any) => {
const [user, setUser] = useState(props.user ? {
...props.user,
loggedIn: false
} : null);
// const checkUser = async () => {
// const userToken = await getJwt();
// if(userToken != ''){
// setUser({
// ...user,
// isLoggedIn: true
// })
// }
// }
// if(user == null)
// {
// checkUser();
// }
const login = async (user: any) : Promise<void> => {
if(user.token == null) {
return;
}
setUser({
...user,
isLoggedIn: true
})
//await setJwt(user.token);
// let token = await getJwt();
//console.log(token);
}
const logOut = () => {
setUser({
user: null,
isLoggedIn: false
})
}
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<UserContext.Provider value={{
user,
login,
logOut,
}}>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</UserContext.Provider>
</SafeAreaProvider>
);
}
}
export default App;