/* ═══════════════════════════════════════════════════════════════ ADMIN LOGIN Deliberately outside PageShell and the site nav. This isn't a page of the website; it's the door to the back office, and it shouldn't carry a banner, a subnav, or a footer site map. Google first, when the server has it set up (/auth/providers says so; it's off until GOOGLE_CLIENT_ID and _SECRET are on the service). It's a plain link: the server sends the browser to Google and back, and a refusal comes back here as ?error=, worded below. Email and password stay underneath as the way in if Google is ever unavailable. ═══════════════════════════════════════════════════════════════ */ import { useEffect, useState } from "react"; import { useLocation, useNavigate, useSearchParams } from "react-router-dom"; import { useAuth } from "../../lib/auth.tsx"; import { ApiError, get } from "../../lib/api.ts"; /* What a ?error= from the Google callback means, in the words the person at the login page needs. */ const GOOGLE_ERRORS: Record = { cancelled: "Google sign-in was cancelled.", expired: "That sign-in took too long or was already used. Try again.", no_account: "There's no admin account for that Google account. Ask a superadmin to add your email.", linked_elsewhere: "That email's admin account is linked to a different Google account.", disabled: "That account has been disabled.", wrong_domain: "Use your @nextgenerationofunity.org Google account.", unverified: "That Google account's email isn't verified.", google_unreachable: "Couldn't reach Google. Try again in a moment.", google_failed: "Google sign-in didn't work. Try again, or use your password.", }; const fieldClass = "w-full rounded-xl border border-muted/50 bg-surface px-4 py-3 text-body " + "outline-none transition-colors focus:border-brand focus:ring-2 focus:ring-brand/25"; export default function AdminLogin() { const { login } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const [searchParams] = useSearchParams(); const googleError = searchParams.get("error"); const [google, setGoogle] = useState(false); useEffect(() => { get("/auth/providers", { ttl: 0 }) .then((data) => setGoogle(Boolean(data.google))) .catch(() => setGoogle(false)); }, []); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState( googleError ? (GOOGLE_ERRORS[googleError] ?? GOOGLE_ERRORS.google_failed) : null, ); const [busy, setBusy] = useState(false); const destination = location.state?.from?.pathname ?? "/admin/home"; async function handleSubmit(event) { event.preventDefault(); if (busy) return; setBusy(true); setError(null); try { await login(email.trim(), password); navigate(destination, { replace: true }); } catch (err) { setError( err instanceof ApiError ? err.message : "Couldn't reach the server. Try again in a moment.", ); setPassword(""); setBusy(false); } } return (

NGU admin

Sign in to edit the site.

{google && ( <> Sign in with Google
or with a password
)} setEmail(e.target.value)} className={`mt-2 ${fieldClass}`} /> setPassword(e.target.value)} className={`mt-2 ${fieldClass}`} /> {error && (

{error}

)}

Accounts are created on the server. Ask whoever runs the box.

); }