-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
71 lines (55 loc) · 1.87 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
import * as React from 'react';
import { StyleSheet, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import WelcomeScreen from './Screens/WelcomeScreen';
import LoginScreen from './Screens/LoginScreen';
import SignupScreen from './Screens/SignupScreen';
import HomeScreen from './Screens/HomeScreen';
import ForgetPassword from './Screens/ForgetPassword';
import { useState } from 'react';
import { getAuth, onAuthStateChanged } from "firebase/auth"
const Stack = createNativeStackNavigator();
export default function App() {
const [isLoggedIn,setIsLoggedIn]=useState(false)
const auth = getAuth();
onAuthStateChanged(auth, (user) => {
if (user) {
setIsLoggedIn(true)
alert('Sign in')
const uid = user.uid;
} else {
setIsLoggedIn(false)
}
});
const AuthStack = () => {
return (
<Stack.Navigator initialRouteName='Welcome'>
<Stack.Screen name='Welcome' options={{ headerShown: false }} component={WelcomeScreen} />
<Stack.Screen name='Login' options={{ headerShown: false }} component={LoginScreen} />
<Stack.Screen name='Signup' options={{ headerShown: false }} component={SignupScreen} />
<Stack.Screen name='forget' options={{ headerShown: false }} component={ForgetPassword} />
</Stack.Navigator>
)
}
return (
<NavigationContainer>
{isLoggedIn?
<Stack.Navigator>
<Stack.Screen name='home' options={{ headerShown: false }} component={HomeScreen} />
</Stack.Navigator>
:<AuthStack/>}
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
horizontal: {
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10,
},
});