import { NextResponse } from "next/server"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { ApiKeyError, deleteApiKey, revealApiKey } from "@/lib/api-keys"; export const dynamic = "force-dynamic"; /** The key's value ("show key" in Settings). */ export const GET = withAuth>(async (_req, { params }) => { const { id } = await params; try { return NextResponse.json({ key: await revealApiKey(id) }, { headers: { "Cache-Control": "no-store" } }); } catch (err) { if (err instanceof ApiKeyError) return apiError(err.status, err.code, err.message); return handleApiError(err); } }); /** Remove a key; running deployments keep accepting it until they restart. */ export const DELETE = withAuth>(async (_req, { params }) => { const { id } = await params; try { await deleteApiKey(id); return new NextResponse(null, { status: 204 }); } catch (err) { if (err instanceof ApiKeyError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });