"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 the create page 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("/docs/create"); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } } return (

MCPedia Admin

{error && (
{error}
)}
setPassword(e.target.value)} className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-700 rounded bg-white dark:bg-zinc-900" required autoFocus />
← Back to home
); }