Files
cruiseLovers/app/index.tsx

30 lines
888 B
TypeScript

import { LoadingSpinner } from '@/assets/components/LoadingSpinner';
import { useAuth } from '@/assets/contexts/useAuth';
import { type Href, router } from 'expo-router';
import { useEffect } from 'react';
import { View } from 'react-native';
import styles from '@/styles/screens/root/index.styles';
export default function Index() {
const { isAuthenticated, isLoading } = useAuth();
useEffect(() => {
if (!isLoading) {
if (isAuthenticated) {
// Se estiver autenticado, redirecionar para home
router.replace('/home' as Href);
} else {
// Se não estiver autenticado, redirecionar para login
router.replace('/login' as Href);
}
}
}, [isAuthenticated, isLoading]);
// Mostrar loading enquanto verifica autenticação
return (
<View style={styles.container}>
<LoadingSpinner size="large" />
</View>
);
}