import React, { useState } from 'react'; import { KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, Text, View, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Ionicons } from '@expo/vector-icons'; import { Button, Field, TextField } from '@/components/ui'; import { useRouter } from 'expo-router'; import { useAuth } from '@/auth/AuthContext'; import { USE_MOCK } from '@/api'; import { useT } from '@/i18n'; import { colors, fontSize, radii, spacing } from '@/theme'; export default function LoginScreen() { const insets = useSafeAreaInsets(); const { signIn } = useAuth(); const router = useRouter(); const t = useT(); const [email, setEmail] = useState(USE_MOCK ? 'j.smith@casadoc.app' : ''); const [password, setPassword] = useState(USE_MOCK ? 'demo' : ''); const [showPass, setShowPass] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function onSignIn() { if (!email.trim() || !password) { setError(t('login.missingFields')); return; } setError(null); setLoading(true); try { await signIn(email.trim(), password); } catch (e: any) { // Unverified is not a wrong password: send them to the code screen. if (e?.code === 'email_not_verified') { router.push(`/verify?email=${encodeURIComponent(email.trim())}`); return; } // The backend's message is English-only; ours says the same, localized. setError(e?.status === 401 || e?.status === 422 ? t('login.failed') : (e?.message ?? t('login.failed'))); } finally { setLoading(false); } } return ( CasaDoc {t('login.tagline')} setShowPass((s) => !s)} style={styles.showPass} hitSlop={8}> {showPass ? t('login.hide') : t('login.show')} {error ? ( {error} ) : null}