-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
69 lines (58 loc) · 2.08 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
import { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import BottomNavigator from './src/components/BottomNavigator';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import useAuthStore from './src/store/AuthStore';
import useUserStore from './src/store/UserStore';
import LandingScreen from './src/screens/Auth/Landing';
import LoginScreen from './src/screens/Auth/Login';
import RegisterScreen from './src/screens/Auth/Register';
import { supabase } from './src/lib/supabase';
import * as UserService from './src/services/UserService';
const Stack = createNativeStackNavigator();
const AuthScreen = () => {
return (
<Stack.Navigator screenOptions={{ header: () => null }}>
<Stack.Screen name="Landing" component={LandingScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Register" component={RegisterScreen} />
</Stack.Navigator>
);
}
const AppScreen = () => {
return (
<BottomNavigator></BottomNavigator>
);
}
function App() {
const authData = useAuthStore(state => state.authData);
const storeAuthData = useAuthStore(state => state.storeAuthData);
const storeUserData = useUserStore(state => state.storeUserData);
useEffect(() => {
async function getSession() {
const { data, error } = await supabase.auth.getSession();
if (data.session && !error) {
storeAuthData(data.session);
const { data: userData, error: userDataError } = await UserService.getUserData(data.session.user.id);
if (userData && !userDataError) {
storeUserData(userData[0]);
} else {
getSession();
}
}
}
getSession();
supabase.auth.onAuthStateChange((_event, session) => {
storeAuthData(session);
})
}, []);
return (
<SafeAreaProvider>
<NavigationContainer>
{authData && authData.user ? <AppScreen /> : <AuthScreen />}
</NavigationContainer>
</SafeAreaProvider>
);
}
export default App;