Files
project_it207_client/app/_layout.tsx
2025-11-20 14:49:39 +07:00

28 lines
766 B
TypeScript

import { Stack, router } from "expo-router";
import { useEffect, useState } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
export default function RootLayout() {
const [isLoading, setIsLoading] = useState(true);
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
const checkAuth = async () => {
const token = await AsyncStorage.getItem("authToken");
setIsLoggedIn(!!token);
setIsLoading(false);
};
checkAuth();
}, []);
if (isLoading) return null;
return (
<Stack>
{!isLoggedIn && <Stack.Screen name="index" options={{ headerShown: false }} />}
{isLoggedIn && <Stack.Screen name="(tabs)" options={{ headerShown: false }} />}
</Stack>
);
}