zioinfo-mail/workspace/guardia-messenger/app/_layout.tsx
DESKTOP-TKLFCPR\ython 777e027553 refactor(structure): move app -> workspace/guardia-messenger
Permission denied on git mv, used robocopy instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 23:53:57 +09:00

32 lines
899 B
TypeScript

import { useEffect } from 'react'
import { Stack, useRouter, useSegments } from 'expo-router'
import { StatusBar } from 'expo-status-bar'
import * as SplashScreen from 'expo-splash-screen'
import { AuthContext, useAuthState } from '../hooks/useAuth'
SplashScreen.preventAutoHideAsync()
export default function RootLayout() {
const auth = useAuthState()
const router = useRouter()
const segments = useSegments()
useEffect(() => {
if (auth.loading) return
SplashScreen.hideAsync()
const inAuth = segments[0] === '(auth)'
if (!auth.token && !inAuth) {
router.replace('/(auth)/login')
} else if (auth.token && inAuth) {
router.replace('/(tabs)')
}
}, [auth.loading, auth.token])
return (
<AuthContext.Provider value={auth}>
<StatusBar style="light" />
<Stack screenOptions={{ headerShown: false }} />
</AuthContext.Provider>
)
}