-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigator.js
118 lines (110 loc) · 3.17 KB
/
navigator.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState, useEffect } from "react";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import HomeScreen from "./screens/Home";
import StoriesScreen from "./screens/Stories";
import SettingsScreen from "./screens/Settings";
import { createStackNavigator } from "@react-navigation/stack";
import Auth from "./screens/Auth";
import Login from "./screens/Login";
import SignUp from "./screens/SignUp";
import { getAuth, onAuthStateChanged } from "firebase/auth";
import ParentsScreen from "./screens/ParentsScreen";
import Profile from "./screens/Profile";
import PromptFlowStartScreen from "./screens/PromptFlowStartScreen";
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
function HomeStackNavigation() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Stories"
component={StoriesScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Parents"
component={ParentsScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Profile"
component={Profile}
options={{ headerShown: false }}
/>
<Stack.Screen
name="PromptFlowStart"
component={PromptFlowStartScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
const AuthStack = () => {
const [isLoading, setIsLoading] = useState(true); // Initially true
const [isAuthenticated, setIsAuthenticated] = useState(false);
useEffect(() => {
console.log("RootStack: useEffect");
const auth = getAuth();
console.log("RootStack: auth", auth);
console.log("RootStack: auth.user", auth.currentUser);
console.log("RootStack: auth.user", auth.currentUser);
const unsubscribe = onAuthStateChanged(auth, (user) => {
if (user) {
// User is logged in
setIsAuthenticated(true);
setIsLoading(false);
} else {
// User is not logged in
setIsAuthenticated(false);
setIsLoading(false);
}
setIsLoading(false);
});
// Cleanup subscription on unmount
console.log("Authentication is: ", isAuthenticated);
return unsubscribe;
}, []);
if (isLoading) {
return null;
}
return (
<Stack.Navigator>
{!isAuthenticated ? (
<>
<Stack.Screen
name="Auth"
component={Auth}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
/>
<Stack.Screen
name="SignUp"
component={SignUp}
options={{ headerShown: false }}
/>
</>
) : (
<Stack.Screen
name="App"
component={HomeStackNavigation}
options={{ headerShown: false }}
/>
)}
</Stack.Navigator>
);
};
export { HomeStackNavigation, AuthStack };