import { createHash } from "node:crypto"; import { createClient } from "@supabase/supabase-js"; import { redirect } from "next/navigation"; import { user } from "@/lib/supabase"; import { Header, Footer } from "@/components/Shell"; export const metadata = { robots: { index: false, follow: false }, referrer: "no-referrer" as const }; function db() { return createClient(process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.SUPABASE_SECRET_KEY!, { auth: { persistSession: false } }); } async function confirm(form: FormData) { "use server"; const token = String(form.get("token") ?? ""); if (!/^[a-f0-9]{64}$/.test(token)) throw new Error("Invalid application link"); const account = await user(); if (!account) redirect(`/log-in?next=${encodeURIComponent(`/moderator-application/${token}`)}`); const database = db(); const { data: profile, error: profileError } = await database.from("profiles").select("username,account_status").eq("id", account.id).single(); if (profileError || !profile || profile.account_status !== "active" || !profile.username) redirect(`/moderator-application/${token}?error=username`); const hash = createHash("sha256").update(token).digest("hex"); const { data, error } = await database.from("moderator_applications").update({ status: "pending", profile_id: account.id }).eq("confirmation_hash", hash).eq("requested_username", profile.username).eq("status", "confirming").gt("expires_at", new Date().toISOString()).select("id").maybeSingle(); if (error || !data) redirect(`/moderator-application/${token}?error=link`); redirect(`/moderator-application/${token}?submitted=1`); } export default async function ApplicationPage({ params, searchParams }: { params: Promise<{ token: string }>; searchParams: Promise<{ submitted?: string; error?: string }> }) { const { token } = await params; if (!/^[a-f0-9]{64}$/.test(token)) return
Invalid application link.
; const account = await user(); if (!account) redirect(`/log-in?next=${encodeURIComponent(`/moderator-application/${token}`)}`); const { submitted, error } = await searchParams; return <>

Moderator application

{submitted ?

Application sent for review.

: <>

Confirm that this MineGeo account belongs to you.

{error &&

{error === "username" ? "Set your username in account settings first." : "This link expired, was already used, or belongs to a different username. Start again in the bot."}

}
}