-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
79 lines (71 loc) · 2.74 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
75
76
77
78
79
import React from "react";
import { useEffect, useState } from "react";
import HomeScreen from "./pages/home-view";
import LoginView from "./pages/login-view";
import CameraScan from "./pages/camera-scan.js";
import PickItems from "./pages/pick-items";
import SignUp from "./pages/sign-up";
import Payment from "./pages/payment-view";
import AddFriends from "./pages/add-friends";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { QueryClient, QueryClientProvider } from "react-query";
import { onAuthStateChanged } from "firebase/auth";
import { ActivityIndicator, View } from "react-native";
import { FIREBASE_AUTH } from "./firebaseConfig";
const Stack = createNativeStackNavigator();
const queryClient = new QueryClient();
function App() {
const [isLoading, setIsLoading] = useState(true);
const [user, setUser] = useState(null);
useEffect(() => {
// Set up the listener for authentication state
const unsubscribe = onAuthStateChanged(FIREBASE_AUTH, (authUser) => {
console.log("Auth state changed. Current user is:", authUser);
if (authUser) {
// User is logged in
console.log("User details:", authUser);
// setUser(authUser);
} else {
// User is logged out
console.log("No user is logged in.");
// setUser(null);
}
setIsLoading(false);
});
// Unsubscribe to the listener when unmounting
return () => unsubscribe();
}, []);
if (isLoading) {
// We haven't finished checking for the user's auth state yet
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
}
return (
<QueryClientProvider client={queryClient}>
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
initialRouteName={user ? "HomeScreen" : "Login"}
>
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="Login" component={LoginView} />
<Stack.Screen name="CameraScan" component={CameraScan} />
<Stack.Screen name="PickItems" component={PickItems} />
<Stack.Screen name="SignUp" component={SignUp} />
<Stack.Screen name="Payment" component={Payment} />
<Stack.Screen name="AddFriends" component={AddFriends} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
</QueryClientProvider>
);
}
export default App;