-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
44 lines (41 loc) · 1.38 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
import AsyncStorage from '@react-native-async-storage/async-storage';
import { StatusBar } from 'expo-status-bar';
import { useEffect, useState } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import LoginModal from './Componets/LoginForm';
import { NavigationContainer } from '@react-navigation/native';
import OS from './Screens/OS';
import NavBar from './Componets/Navigation/NavBar';
export default function App() {
const [username, setUsername] = useState('');
const [userExists, setUserExists] = useState(false);
const [visible, setVisible] = useState(true);
useEffect(() => {
const checkUserExists = async () => {
const user = await AsyncStorage.getItem('User');
setUserExists(!!user);
setUsername(user || '');
if (user == '')
setVisible(true);
};
checkUserExists();
}, []);
/*=================LOGIN HANDLER===========================*/
const LoginHandler = (user) => {
setVisible(false);
setUsername(user.USERNAME);
AsyncStorage.setItem('User', JSON.stringify(user));
return (
<NavigationContainer>
<NavBar />
<StatusBar style="auto" />
</NavigationContainer>
);
}
return userExists ? (
<NavigationContainer>
<NavBar />
<StatusBar style="auto" />
</NavigationContainer>
) : <LoginModal visible={visible} onLogin={(user) => LoginHandler(user)} />;
}