forked from linus1703/expo-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
49 lines (46 loc) · 1.44 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
43
44
45
46
47
48
49
import { StatusBar } from "expo-status-bar";
import { NativeBaseProvider, useToast } from "native-base";
import { SafeAreaProvider } from "react-native-safe-area-context";
import useCachedResources from "./app/hooks/useCachedResources";
import useColorScheme from "./app/hooks/useColorScheme";
import Navigation from "./app/navigation/RootNavigator";
import { supabase } from "./app/services/supabase";
import { useEffect } from "react";
import useAuthStore from "./app/stores/AuthStore";
export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
const toast = useToast();
const { setSession, logout } = useAuthStore();
useEffect(() => {
supabase.auth
.refreshSession()
.then(async (session) => {
console.log("session", session);
setSession(session.data.session);
if (session.error) await logout();
})
.catch(async (error) => {
console.log("error", error);
await toast.show({
variant: "left-accent",
placement: "top",
title: "Error",
description: "Please login again",
bg: "danger.500",
});
});
}, []);
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<NativeBaseProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</NativeBaseProvider>
</SafeAreaProvider>
);
}
}