p 1 and 2 compeleted
This commit is contained in:
1 parent
6adb541967
commit
3573709d99
28 files changed
+2533
-240
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import { Tabs, useRouter, useSegments } from "expo-router";
|
||||
import { useAuth } from "@clerk/clerk-expo";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { CustomTabBar } from "../../components/CustomTabBar";
|
||||
import { fitnessProfileApi } from "../../api/fitnessProfile";
|
||||
import log from "../../utils/logger";
|
||||
|
||||
export default function TabLayout() {
|
||||
const { isSignedIn, isLoaded } = useAuth();
|
||||
const { isSignedIn, isLoaded, getToken } = useAuth();
|
||||
const router = useRouter();
|
||||
const segments = useSegments();
|
||||
const [onboardingChecked, setOnboardingChecked] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoaded) return;
|
||||
@@ -16,10 +19,40 @@ export default function TabLayout() {
|
||||
if (!isSignedIn && !inAuthGroup) {
|
||||
// Redirect to sign-in if not authenticated
|
||||
router.replace("/(auth)/sign-in");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user has completed onboarding
|
||||
if (isSignedIn && !onboardingChecked) {
|
||||
checkOnboardingStatus();
|
||||
}
|
||||
}, [isSignedIn, isLoaded, segments]);
|
||||
|
||||
if (!isLoaded || !isSignedIn) {
|
||||
const checkOnboardingStatus = async () => {
|
||||
try {
|
||||
const token = await getToken();
|
||||
if (!token) {
|
||||
log.warn("No token available for onboarding check");
|
||||
return;
|
||||
}
|
||||
|
||||
const hasProfile = await fitnessProfileApi.checkProfileExists(token);
|
||||
|
||||
if (!hasProfile) {
|
||||
// User hasn't completed onboarding, redirect to onboarding screen
|
||||
log.info("User has not completed onboarding, redirecting");
|
||||
router.replace("/(auth)/onboarding");
|
||||
} else {
|
||||
setOnboardingChecked(true);
|
||||
}
|
||||
} catch (error) {
|
||||
log.error("Failed to check onboarding status", error);
|
||||
// On error, allow access (fail open to prevent blocking legitimate users)
|
||||
setOnboardingChecked(true);
|
||||
}
|
||||
};
|
||||
|
||||
if (!isLoaded || !isSignedIn || !onboardingChecked) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user