"use client"; import { useState } from "react"; import { useI18n } from "../../components/I18nProvider"; export default function LoginPage() { const { t } = useI18n(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [success, setSuccess] = useState(false); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); setSuccess(false); setLoading(true); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { setError(data.error || "Login failed"); } else { try { setSuccess(true); localStorage.setItem("auth_token", data.token); document.cookie = `auth_token=${data.token}; path=/; SameSite=Lax`; window.location.href = "/"; } catch (err) { // ignore storage errors } } } catch (err) { setError("Login failed"); } finally { setLoading(false); } } return (

{t("loginTitle")}

{t("forgotCta")}

{success ? (

{t("loginSuccess")}

) : null} {error ?

{error}

: null}
); }