-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
90 lines (80 loc) · 2.51 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { TailwindProvider } from "tailwindcss-react-native";
import { NavigationContainer } from "@react-navigation/native";
import { ReactElement, useEffect, useState } from "react";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import Main from "./screens/Main";
import Login from "./screens/Login";
import Chat from "./screens/Chat";
import Notice from "./screens/Notice";
import SplashScreen from "./screens/SplashScreen";
import { User, onAuthStateChanged } from "firebase/auth";
import { auth } from "./firebase";
const Stack = createNativeStackNavigator();
export default function App(): ReactElement | null {
const [authState, setAuthState] = useState<
"isLoading" | "isAuthenticated" | "isNotAuthenticated"
>("isLoading");
const [userInfo, setUserInfo] = useState<User | null>(null);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user: User): void => {
if (user) {
setUserInfo(user);
setAuthState("isAuthenticated");
} else {
setAuthState("isNotAuthenticated");
}
});
return unsubscribe;
}, []);
if (authState == "isLoading") {
return <SplashScreen />
}
return (
<NavigationContainer>
<TailwindProvider>
<Stack.Navigator>
{/* Screens for unauthenticated users */}
{authState == "isNotAuthenticated" && (
<>
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
/>
</>
)}
{/* Screens for authenticated users */}
{authState == "isAuthenticated" && (
<>
<Stack.Screen
name="Main"
component={Main}
options={{ headerShown: false }}
/>
</>
)}
{/* Screens for authenticated users */}
{authState == "isAuthenticated" && (
<>
<Stack.Screen
name="Chat"
component={Chat}
options={{ headerShown: false }}
/>
</>
)}
{/* Screens for authenticated users */}
{authState == "isAuthenticated" && (
<>
<Stack.Screen
name="Notice"
component={Notice}
options={{ headerShown: false }}
/>
</>
)}
</Stack.Navigator>
</TailwindProvider>
</NavigationContainer>
);
}