-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
74 lines (58 loc) · 1.98 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
71
72
73
74
import 'react-native-gesture-handler'
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import React, { useEffect, useState, createContext } from 'react'
import { StyleSheet } from 'react-native'
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { auth } from './firebase'
import NavigationHome from './screens/NavigationHome';
import NavigationLogin from './screens/NavigationLogin';
import AsyncStorage from '@react-native-async-storage/async-storage';
Stack = createNativeStackNavigator()
function App() {
const [userFullName, setUserFullName] = useState('')
const storeStringData = async (key, value) => {
try {
await AsyncStorage.setItem(key, value)
console.log(`Successfully stored ${key} : ${value}`)
} catch (e) {
console.log("Stored UID Successfully")
// saving error
}
}
console.log(auth)
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Handle user state changes
function onAuthStateChanged(user) {
setUser(user);
if (user){
storeStringData("userID", user.uid)
console.log(user)
storeStringData("userFullName", user.displayName)
}
else storeStringData("userID", null)
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth.onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
}, []);
if (!user) {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen options={{ headerShown: false }} name="LoginScreenStack" component={NavigationLogin} />
</Stack.Navigator>
</NavigationContainer>
)
}
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen options={{ headerShown: false }} name="HomeScreenStack" component={NavigationHome} />
</Stack.Navigator>
</NavigationContainer>
)
}
export default App
const styles = StyleSheet.create({})