import { useState } from "react"; import { View, Text, TextInput, Pressable, StyleSheet } from "react-native"; import { useRouter } from "expo-router"; import { useAuth } from "@/auth"; import { ApiError } from "@/api"; import { C } from "@/theme"; export default function Login() { const { login } = useAuth(); const router = useRouter(); const [user, setUser] = useState(""); const [password, setPassword] = useState(""); const [totp, setTotp] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const submit = async (): Promise => { setBusy(true); setError(null); try { await login(user, password, totp); router.replace("/(tabs)/chat"); } catch (err) { setError(err instanceof ApiError && err.status === 429 ? "Trop de tentatives." : "Identifiants invalides."); } finally { setBusy(false); } }; return ( CHLOVA Accès propriétaire — authentification forte. {error && {error}} {busy ? "Connexion…" : "Se connecter"} ); } const s = StyleSheet.create({ wrap: { flex: 1, justifyContent: "center", padding: 24, gap: 12, backgroundColor: C.bg }, title: { color: C.accent, fontSize: 32, fontWeight: "700", letterSpacing: 2 }, sub: { color: C.muted, marginBottom: 8 }, input: { backgroundColor: C.surface2, borderColor: C.border, borderWidth: 1, borderRadius: 8, color: C.fg, padding: 12 }, error: { color: C.danger }, btn: { backgroundColor: C.accent, borderRadius: 8, padding: 14, alignItems: "center", marginTop: 4 }, btnDisabled: { opacity: 0.5 }, btnText: { color: C.bg, fontWeight: "600" }, });