"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); useEffect(() => { fetch("/api/v1/auth/me", { credentials: "include" }) .then((r) => { if (r.ok) router.push("/dashboard"); }) .catch(() => {}); }, [router]); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(""); try { const res = await fetch("/api/v1/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ email, password }), }); if (!res.ok) { const text = await res.text(); let message = "Inloggen mislukt"; try { const data = JSON.parse(text); message = data.error?.message ?? message; } catch { message = text.slice(0, 120) || `Inloggen mislukt (HTTP ${res.status})`; } throw new Error(message); } window.location.assign("/dashboard"); } catch (err) { setError(err instanceof Error ? err.message : "Inloggen mislukt"); setLoading(false); } } return (
MC

VMC

Authenticated access // ops

{error &&
{error}
}
setEmail(e.target.value)} required autoComplete="username" />
setPassword(e.target.value)} required autoComplete="current-password" />
); }