import Head from "next/head"; import { useRouter } from "next/router"; import { useState } from "react"; import CookieBanner from "../../components/cookieBanner"; import Footer from "../../components/footer"; import Header from "../../components/header"; import { readAdminSessionCookie, validateAdminSession } from "../../lib/admin/adminAuth"; const AdminLoginPage = () => { const router = useRouter(); const [passphrase, setPassphrase] = useState(""); const [error, setError] = useState(""); const [submitting, setSubmitting] = useState(false); const handleSubmit = async (event) => { event.preventDefault(); setError(""); setSubmitting(true); try { const response = await fetch("/api/admin/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "same-origin", body: JSON.stringify({ passphrase }) }); if (!response.ok) { setError("Sign in failed. Check the details and try again."); return; } await router.replace("/admin"); } catch (_error) { setError("Sign in failed. Check the details and try again."); } finally { setSubmitting(false); } }; return (
Administrative sign in

Administrative sign in

{error && (

There is a problem

{error}

)}
{error && (

Error: {" "} {error}

)} setPassphrase(event.target.value) } aria-describedby={ error ? "admin-passphrase-error" : undefined } aria-invalid={error ? "true" : undefined} disabled={submitting} required />
); }; export const getServerSideProps = async ({ req }) => { const adminSession = readAdminSessionCookie(req); if (validateAdminSession(adminSession)) { return { redirect: { destination: "/admin", permanent: false } }; } return { props: {} }; }; export default AdminLoginPage;