-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
66 lines (61 loc) · 2.01 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
import React, { useState, useEffect, useContext } from "react"
import { SafeAreaProvider } from "react-native-safe-area-context"
import { NavigationContainer } from "@react-navigation/native"
import { createStackNavigator } from "@react-navigation/stack"
import { StyleSheet, ActivityIndicator, Button } from "react-native"
import LoginScreenNavigator from "./src/components/navigation/LoginScreenNavigator"
import BottomTabNavigator from "./src/components/navigation/BottomTabNavigator"
import { firebase } from "./src/firebase/config"
import { AuthContext, AuthProvider } from "./src/context/AuthProvider"
const Stack = createStackNavigator()
export default function App() {
const [user, setUser] = useState(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
const userRef = firebase.firestore().collection("users")
firebase.auth().onAuthStateChanged((currentUser) => {
if (currentUser) {
userRef
.doc(currentUser.uid)
.get()
.then((document) => {
const userData = document.data()
setLoading(false)
setUser(userData)
})
.catch((e) => {
setLoading(true)
setUser(null)
})
} else {
setLoading(true)
setUser(null)
}
})
}, [])
return (
<SafeAreaProvider>
<NavigationContainer>
{user ? (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home">
{(props) => <BottomTabNavigator {...props} user={user} />}
</Stack.Screen>
</Stack.Navigator>
) : (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Root" component={LoginScreenNavigator} />
</Stack.Navigator>
)}
</NavigationContainer>
</SafeAreaProvider>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
})