polished and finalised onboarding flow

This commit is contained in:
Chris Sanden
2026-05-05 17:36:34 +02:00
parent 2bb2ac63a0
commit 9bb3bb1163
10 changed files with 310 additions and 57 deletions

View File

@@ -1,3 +1,4 @@
import { getSetupStatus } from "@/lib/setupStatus";
import { supabase } from "@/lib/supabase";
import { Session } from "@supabase/supabase-js";
import * as Notifications from 'expo-notifications';
@@ -32,6 +33,8 @@ function UseNotificationObserver() {
export default function TabLayout() {
const [session, SetSession] = useState<Session | null>(null)
const [loading, SetLoading] = useState(true);
const [setupChecked, setSetupChecked] = useState(false);
const [needsSetup, setNeedsSetup] = useState(false);
UseNotificationObserver();
@@ -51,7 +54,29 @@ export default function TabLayout() {
return () => sub.subscription.unsubscribe();
}, []);
if (loading) {
useEffect(() => {
const checkSetupStatus = async () => {
if (!session?.user.id) {
setNeedsSetup(false);
setSetupChecked(true);
return;
}
try {
const setupStatus = await getSetupStatus(session.user.id);
setNeedsSetup(!setupStatus.isSetupComplete);
} catch {
setNeedsSetup(true);
} finally {
setSetupChecked(true);
}
};
setSetupChecked(false);
void checkSetupStatus();
}, [session?.user.id]);
if (loading || !setupChecked) {
return null;
}
@@ -59,6 +84,10 @@ export default function TabLayout() {
return <Redirect href="/login" />;
}
if (needsSetup) {
return <Redirect href="/setup" />;
}
return (
<Tabs
screenOptions={{
@@ -68,4 +97,4 @@ export default function TabLayout() {
<Tabs.Screen name="subjects" options={{title: "Subjects"}} />
</Tabs>
);
}
}