-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
58 lines (52 loc) · 2.26 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
import React, { useState, useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { Provider as PaperProvider } from 'react-native-paper';
import { onAuthStateChanged } from 'firebase/auth';
import { auth } from './Firebase/FirebaseSetup';
import { ContextProvider } from './Context/context';
import AuthStateListener from './Context/AuthStateListener';
// Importing screens and navigators
import LoginScreen from './screens/LogInScreen';
import SignupScreen from './screens/SignUpScreen';
import ExploreScreen from './screens/ExploreScreen';
import BottomNavigator from './navigation/BottomNavigator';
import RecipeListScreen from './screens/RecipeListScreen';
import RecipeDetailScreen from './screens/RecipeDetailScreen';
const Stack = createNativeStackNavigator();
export default function App() {
const [isUserAuthenticated, setIsUserAuthenticated] = useState(false);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setIsUserAuthenticated(!!user); // Set to true if a user is authenticated
});
return unsubscribe; // Cleanup the listener on unmount
}, []);
return (
<ContextProvider>
<AuthStateListener>
<PaperProvider>
<NavigationContainer>
<Stack.Navigator>
{isUserAuthenticated ? <>
<Stack.Screen
name="BottomNavigator"
component={BottomNavigator}
options={{ headerShown: false }}
/>
<Stack.Screen name="Explore" component={ExploreScreen} />
<Stack.Screen name="RecipeList" component={RecipeListScreen} />
<Stack.Screen name="RecipeDetail" component={RecipeDetailScreen} />
</> : <>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Signup" component={SignupScreen} />
{/* <Stack.Screen name="ForgotPassword" component={ForgotPasswordScreen} /> */}
</>
}
</Stack.Navigator>
</NavigationContainer>
</PaperProvider>
</AuthStateListener>
</ContextProvider>
);
}