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 (
); }