import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate } from "react-router-dom"; import { useAuthStore } from "@/stores/auth-store"; import { login } from "@/api/auth"; export function LoginForm() { const { t } = useTranslation(); const navigate = useNavigate(); const setAuth = useAuthStore((s) => s.setAuth); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [rememberMe, setRememberMe] = useState(false); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setLoading(true); try { const data = await login(email, password, rememberMe); setAuth(data.user, data.access_token, data.refresh_token); navigate("/"); } catch (err: unknown) { const msg = (err as { response?: { data?: { detail?: string } } })?.response?.data?.detail || t("auth.errors.invalidCredentials"); setError(msg); } finally { setLoading(false); } }; return (
{error && (
{error}
)}
setEmail(e.target.value)} required className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" placeholder="name@example.com" />
setPassword(e.target.value)} required className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" />
setRememberMe(e.target.checked)} className="h-4 w-4 rounded border-input" />

{t("auth.noAccount")}{" "} {t("auth.register")}

); }