"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; // Simple admin login form. POSTs password to /api/auth/login. // On success, the API sets an HTTP-only cookie. We don't touch the cookie // client-side (it's HttpOnly) — just redirect to /create after login. export default function LoginPage() { const router = useRouter(); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password }), }); if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.error ?? "Login failed"); } router.push("/create"); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } } return (

Admin Login

Enter your admin password to manage documents.

{error && (
{error}
)}
setPassword(e.target.value)} className="w-full px-3 py-2 bg-[#0f1011] border border-[#23252a] rounded text-[#f7f8f8] focus:outline-none focus:border-[#5e6ad2] focus:ring-1 focus:ring-[#5e6ad2]" required autoFocus />
← Back to home
); }