feat: implement authentication flow and session management

- Update RootLayout to handle authentication state and redirect users based on their auth status.
- Create an Index component to redirect unauthenticated users to the login page.
- Modify ApiAuthRepository to fetch user session data using access and refresh tokens.
- Introduce a new container file to manage use case instances for authentication and filament operations.
- Enhance authStore to validate tokens and fetch user data from the API.
- Add babel-plugin-module-resolver for improved module imports.
- Update package.json scripts for running the app on Android and iOS.
- Add expo-camera dependency for camera functionalities.
- Update tsconfig.json to include infrastructure path mapping.
This commit is contained in:
2026-03-14 13:22:17 -03:00
parent d7fb768d3b
commit 416e13893c
68 changed files with 1778 additions and 99 deletions
+7 -3
View File
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { View, Text, Image, StyleSheet, TouchableOpacity, Alert } from 'react-native';
import { View, Text, StyleSheet, TouchableOpacity, Alert } from 'react-native';
import { Link, useRouter } from 'expo-router';
import { useForm, Controller } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
@@ -9,6 +9,8 @@ import { Screen } from '@presentation/components/layout/Screen';
import { Input } from '@presentation/components/ui/Input';
import { Button } from '@presentation/components/ui/Button';
import { colors, typography, spacing } from '@shared/theme';
import { loginUseCase } from '@infrastructure/container';
import { useAuthStore } from '@store/authStore';
const schema = z.object({
email: z.string().email('E-mail inválido'),
@@ -23,6 +25,7 @@ type FormData = z.infer<typeof schema>;
*/
export default function LoginScreen(): React.ReactElement {
const router = useRouter();
const setSession = useAuthStore((s) => s.setSession);
const [isLoading, setIsLoading] = useState(false);
const [isGoogleLoading, setIsGoogleLoading] = useState(false);
@@ -34,10 +37,11 @@ export default function LoginScreen(): React.ReactElement {
async function onSubmit(data: FormData): Promise<void> {
setIsLoading(true);
try {
// TODO: injetar LoginUseCase via container de DI
console.log('login', data);
const session = await loginUseCase.execute(data);
await setSession(session);
router.replace('/(app)/(tabs)/home');
} catch (err) {
console.error('login error', err);
Alert.alert('Erro', 'E-mail ou senha incorretos.');
} finally {
setIsLoading(false);