// Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: chat.spboucher.ai "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; export default function LoginPage() { const router = useRouter(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); setError(null); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); const json = await res.json().catch(() => ({})); if (!res.ok) { setError(json.error ?? "Sign-in failed. Try again."); setBusy(false); return; } router.replace("/"); router.refresh(); } catch { setError("Could not reach the server. Check your connection and try again."); setBusy(false); } } return (
chat.spboucher.ai

Private instrument. Sign in to continue.

setUsername(e.target.value)} /> setPassword(e.target.value)} /> {error &&

{error}

}
); }