import { Metadata } from "next"; import { BadgeCheck, ShieldX } from "lucide-react"; import { Navbar } from "@/components/layout/Navbar"; import { Footer } from "@/components/layout/Footer"; import { apiFetch } from "@/lib/api"; import { formatDate } from "@/lib/date"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "Verify a certificate", robots: { index: false }, }; type Verification = { valid: boolean; revoked?: boolean; name?: string; event?: string; completedOn?: string; issuedAt?: string }; // Public check for the QR code / code printed on a completion certificate. Shows only the // name, event and dates — nothing else about the person. export default async function VerifyCertificatePage({ params }: { params: Promise<{ code: string }> }) { const { code } = await params; let result: Verification = { valid: false }; try { result = await apiFetch(`/api/attendance/certificates/verify/${encodeURIComponent(code)}`, { nextOptions: { cache: "no-store" } }); } catch { result = { valid: false }; } return (
{result.valid ? ( <>

Valid certificate

{result.name} completed

{result.event}

{result.completedOn && <>Completed {formatDate(new Date(result.completedOn))} · } {result.issuedAt && <>Issued {formatDate(new Date(result.issuedAt))}}

) : ( <>

{result.revoked ? "This certificate was withdrawn" : "Certificate not found"}

{result.revoked ? "The organiser has withdrawn this certificate, so it's no longer valid." : "Check the code on the certificate and try again. Codes look like K7M2Q-9XRTB."}

)}

{decodeURIComponent(code).toUpperCase()}

); }