Archived
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
62 lines
2.7 KiB
TypeScript
62 lines
2.7 KiB
TypeScript
import { Metadata } from "next";
|
|
import { BadgeCheck, ShieldX } from "lucide-react";
|
|
import { Navbar } from "@/components/layout/Navbar";
|
|
import { Footer } from "@/components/layout/Footer";
|
|
import { formatDate } from "@/lib/date";
|
|
import { apiV2Data } from "@/lib/apiV2";
|
|
|
|
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 (apiV2Data("get", "/certificates/verify/{code}", { params: { code: code }, nextOptions: { cache: "no-store" } }) as Promise<Verification>);
|
|
} catch {
|
|
result = { valid: false };
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen flex flex-col">
|
|
<Navbar />
|
|
<main className="flex-1 py-12 px-4 max-w-lg mx-auto w-full">
|
|
<div className="border rounded-xl p-6 bg-white shadow-sm text-center">
|
|
{result.valid ? (
|
|
<>
|
|
<BadgeCheck className="w-12 h-12 text-green-600 mx-auto mb-3" />
|
|
<h1 className="text-xl font-semibold text-gray-900">Valid certificate</h1>
|
|
<p className="text-gray-700 mt-3"><span className="font-semibold">{result.name}</span> completed</p>
|
|
<p className="text-lg font-medium text-brand-700 mt-1">{result.event}</p>
|
|
<p className="text-sm text-gray-500 mt-3">
|
|
{result.completedOn && <>Completed {formatDate(new Date(result.completedOn))} · </>}
|
|
{result.issuedAt && <>Issued {formatDate(new Date(result.issuedAt))}</>}
|
|
</p>
|
|
</>
|
|
) : (
|
|
<>
|
|
<ShieldX className="w-12 h-12 text-red-500 mx-auto mb-3" />
|
|
<h1 className="text-xl font-semibold text-gray-900">{result.revoked ? "This certificate was withdrawn" : "Certificate not found"}</h1>
|
|
<p className="text-sm text-gray-500 mt-3">
|
|
{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."}
|
|
</p>
|
|
</>
|
|
)}
|
|
<p className="text-xs text-gray-500 mt-6 font-mono">{decodeURIComponent(code).toUpperCase()}</p>
|
|
</div>
|
|
</main>
|
|
<Footer />
|
|
</div>
|
|
);
|
|
}
|