- Add EmailTokenService for handling email verification and password reset tokens. - Create EmailService for sending verification and reset emails via SMTP. - Update AuthService to handle email verification status during login. - Modify user registration to redirect to a check email screen instead of issuing a token. - Implement resend verification email functionality. - Add deep link handling for email verification and password reset in the mobile app. - Update mobile app routes and components to support new email verification flow. - Enhance error handling for unverified emails during login attempts. - Update configuration to include SMTP settings for email service.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { Stack, useRouter, useSegments } from 'expo-router';
|
|
import { StatusBar } from 'expo-status-bar';
|
|
import { useAuthStore } from '@store/authStore';
|
|
|
|
/**
|
|
* Root layout do expo-router.
|
|
* Carrega a sessão armazenada e controla o fluxo auth vs app.
|
|
*/
|
|
export default function RootLayout(): React.ReactElement | null {
|
|
const { loadStoredSession, isLoading, isAuthenticated } = useAuthStore();
|
|
const router = useRouter();
|
|
const segments = useSegments();
|
|
|
|
useEffect(() => {
|
|
loadStoredSession();
|
|
}, [loadStoredSession]);
|
|
|
|
useEffect(() => {
|
|
if (isLoading) return;
|
|
const inAuthGroup = segments[0] === '(auth)';
|
|
const inPublicRoute = segments[0] === 'verify-email' || segments[0] === 'filament';
|
|
if (isAuthenticated && inAuthGroup) {
|
|
router.replace('/(app)/(tabs)/home');
|
|
} else if (!isAuthenticated && !inAuthGroup && !inPublicRoute) {
|
|
router.replace('/(auth)/login');
|
|
}
|
|
}, [isAuthenticated, isLoading, segments, router]);
|
|
|
|
if (isLoading) return null;
|
|
|
|
return (
|
|
<>
|
|
<StatusBar style="light" backgroundColor="transparent" translucent />
|
|
<Stack screenOptions={{ headerShown: false, contentStyle: { backgroundColor: '#1E1B18' } }}>
|
|
<Stack.Screen name="index" />
|
|
<Stack.Screen name="(auth)" />
|
|
<Stack.Screen name="(app)" />
|
|
<Stack.Screen name="verify-email" />
|
|
<Stack.Screen name="filament/[id]" />
|
|
</Stack>
|
|
</>
|
|
);
|
|
}
|