Merge pull request #35 from Dvorinka/fix/mobile-auth-gate

fix(mobile): gate authed routes — cold-start redbox fix
This commit is contained in:
Tomáš Dvořák authored and GitHub committed 2026-10-09 05:49:29 +02:00
commit dca8aaa7b3
2 files changed
+13 -7

No files matched your search

+9 -6
View File
@@ -19,10 +19,11 @@ function AuthGate() {
useEffect(() => { useEffect(() => {
if (!ready) return; if (!ready) return;
const inLogin = segments[0] === 'login'; const inLogin = segments[0] === 'login';
if (!api && !inLogin) router.replace('/login'); if (api && inLogin) router.replace('/');
else if (api && inLogin) router.replace('/');
}, [ready, api, segments, router]); }, [ready, api, segments, router]);
if (!ready) return null;
return ( return (
<Stack <Stack
screenOptions={{ screenOptions={{
@@ -31,11 +32,13 @@ function AuthGate() {
contentStyle: { backgroundColor: colors.bg }, contentStyle: { backgroundColor: colors.bg },
}} }}
> >
<Stack.Protected guard={!!api}>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="project/[id]" options={{ title: 'Project' }} />
<Stack.Screen name="service/[id]" options={{ title: 'Service' }} />
<Stack.Screen name="service/logs" options={{ title: 'Logs' }} />
</Stack.Protected>
<Stack.Screen name="login" options={{ headerShown: false }} /> <Stack.Screen name="login" options={{ headerShown: false }} />
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="project/[id]" options={{ title: 'Project' }} />
<Stack.Screen name="service/[id]" options={{ title: 'Service' }} />
<Stack.Screen name="service/logs" options={{ title: 'Logs' }} />
</Stack> </Stack>
); );
} }
+4 -1
View File
@@ -1,5 +1,8 @@
import { Redirect } from 'expo-router'; import { Redirect } from 'expo-router';
import { useSession } from '../session';
export default function Index() { export default function Index() {
return <Redirect href="/(tabs)" />; const { ready, api } = useSession();
if (!ready) return null;
return <Redirect href={api ? '/(tabs)' : '/login'} />;
} }