-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
42 lines (37 loc) · 1.4 KB
/
App.tsx
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
import 'react-native-url-polyfill/auto';
import { useState, useEffect } from 'react';
import { supabase } from './app/lib/initSupabase';
import { Session } from '@supabase/supabase-js';
import { NavigationContainer } from '@react-navigation/native';
import AuthStack from './app/navigation/AuthStack';
import { AppContext } from './app/context/AppContext';
import MainStack from './app/navigation/MainStack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
export default function App() {
const queryClient = new QueryClient();
const [session, setSession] = useState<Session | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
setLoading(true);
supabase.auth.getSession().then(({ data: { session } }) => {
setSession(session);
setLoading(false);
});
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session);
});
}, []);
const Auth = () => (session && session.user ? <MainStack /> : <AuthStack />);
return (
<QueryClientProvider client={queryClient}>
<AppContext.Provider value={{ session, loading }}>
<NavigationContainer>
<SafeAreaProvider style={{ flex: 1 }}>
<Auth />
</SafeAreaProvider>
</NavigationContainer>
</AppContext.Provider>
</QueryClientProvider>
);
}