crud for tasks + auth
This commit is contained in:
40
app/(tabs)/_layout.tsx
Normal file
40
app/(tabs)/_layout.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { Session } from "@supabase/supabase-js";
|
||||
import { Redirect, Tabs } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function TabLayout() {
|
||||
const [session, SetSession] = useState<Session | null>(null)
|
||||
const [loading, SetLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const loadSession = async () => {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
SetSession(data.session ?? null);
|
||||
SetLoading(false);
|
||||
}
|
||||
loadSession();
|
||||
|
||||
const { data: sub } = supabase.auth.onAuthStateChange((_event, newSession) => {
|
||||
SetSession(newSession);
|
||||
SetLoading(false);
|
||||
});
|
||||
|
||||
return () => sub.subscription.unsubscribe();
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return <Redirect href="/createUser" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Tabs>
|
||||
<Tabs.Screen name="index" options={{title: "Today"}} />
|
||||
<Tabs.Screen name="tasks" options={{title: "Tasks"}} />
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user