import { NextResponse } from "next/server"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { ApiKeyBody, ApiKeyError, createApiKey, listApiKeys } from "@/lib/api-keys"; export const dynamic = "force-dynamic"; /** Keys without their values (only the last characters). */ export const GET = withAuth(async () => NextResponse.json(await listApiKeys())); /** Add a key (generated when `key` is missing); the response carries the full key once. */ export const POST = withAuth(async (req) => { try { return NextResponse.json(await createApiKey(ApiKeyBody.parse(await req.json())), { status: 201 }); } catch (err) { if (err instanceof ApiKeyError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });