Ok it might work

This commit is contained in:
2026-04-25 12:08:14 +02:00
parent 928db54b3e
commit 858ee5e28b
10 changed files with 229 additions and 67 deletions

View File

@@ -1,29 +1,32 @@
import { BirthdaysProvider } from "@/context/birthdays-context";
import { useAuth } from "@/context/auth-context";
import { Stack, router, useRootNavigationState, useSegments } from "expo-router";
import { useEffect } from "react";
import React, { useEffect } from "react";
import LoadingScreen from "./loading-screen";
export default function RootLayout() {
const { user, isHydrated } = useAuth();
const navigationState = useRootNavigationState();
const segments = useSegments();
const [loaded, setLoaded] = React.useState(false);
useEffect(() => {
if (!isHydrated || !navigationState?.key) {
return;
}
if (!isHydrated || !navigationState?.key) return;
const inAuthGroup = segments[0] === "(auth)";
const inAuthGroup = segments.length === 0;
if (!user && !inAuthGroup) {
router.replace("/(auth)/login");
return;
}
if (!user) {
router.replace("/(auth)/login");
} else if (inAuthGroup) {
router.replace("/(tabs)");
}
if (user && inAuthGroup) {
router.replace("/(tabs)");
}
}, [isHydrated, navigationState?.key, segments, user]);
setLoaded(true); // 👈 ALWAYS run this
}, [isHydrated, navigationState?.key, segments, user]);
if(!loaded) {
return (<LoadingScreen />); // or a loading spinner
}
return (
<BirthdaysProvider>