import React, { useState } from 'react'; import { View, Text, StyleSheet, ScrollView, KeyboardAvoidingView, Platform, Alert, } from 'react-native'; import { Link, router } from 'expo-router'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useThemeColor } from '@/hooks/use-theme-color'; import { Button, Input } from '@/components/ui'; import { useAuth } from '@/context/AuthContext'; import { apiClient, User } from '@/lib/api'; export default function LoginScreen() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [errors, setErrors] = useState<{ email?: string; password?: string }>({}); const { login, isLoading } = useAuth(); const textColor = useThemeColor({}, 'text'); const backgroundColor = useThemeColor({}, 'background'); const tintColor = useThemeColor({}, 'tint'); const validateForm = () => { const newErrors: { email?: string; password?: string } = {}; if (!email) { newErrors.email = 'Email é obrigatório'; } else if (!/\S+@\S+\.\S+/.test(email)) { newErrors.email = 'Por favor, use um email válido'; } if (!password) { newErrors.password = 'Senha é obrigatória'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleLogin = async () => { if (!validateForm()) return; try { await login(email, password); router.replace('/'); } catch (error: any) { console.log("LOGIN error: ", error) Alert.alert('Erro: ', 'Falha ao fazer login'); } }; return ( Bem vindo de volta Logue na sua conta nexo