-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
70 lines (52 loc) · 1.9 KB
/
App.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useState } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Index from './navigation/Index'
export default function App() {
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
const [isFirstTime, setIsFirstTime] = React.useState(null)
// ---------- checking wheather the user open app first time -------
const checkIsFirst = async () => {
await AsyncStorage.getItem('isOldUser')
.then((data) => {
if (data === 'true') {
setIsFirstTime(false)
if (initializing) setInitializing(false);
} else {
setIsFirstTime(true)
AsyncStorage.setItem('isOldUser', 'true');
if (initializing) setInitializing(false);
}
})
}
checkIsFirst();
// ----- if user is old check wheather is he authenticated or not ---------
if (!isFirstTime) {
checkIsAuthenticated();
}
async function checkIsAuthenticated() {
await AsyncStorage.getItem('isLogined')
.then((data) => {
if (data === 'true') {
setUser(true)
} else if (data === 'false') {
setUser(false)
} else {
setUser(false)
}
})
if (initializing) setInitializing(false);
}
// ------- navigate user as per check done above -------
if (initializing) {
return null
}
if (isFirstTime) {
return (<Index firstPage='OnBoarding' />);
} else if (user === false) {
return (<Index firstPage='Login' />);
} else if (user) {
return (<Index firstPage='Home' />);
}
return (null)
}