import { gateOrUser } from "@/auth/api"; import { resetAndSeed } from "@/db/seed"; const JSON_HEADERS = { "content-type": "application/json" }; /** * Test-only database reset. * * Two gates, both required: * 1. `ALLOW_DEV_RESET=true` must be set explicitly. This keeps a destructive * truncate + reseed out of any deployment that did not ask for it. * 2. The caller must be a signed-in admin (`admin.settings`). * * E2E sets `ALLOW_DEV_RESET=true` in `playwright.config.ts`; production * compose does not. */ export const POST = async () => { if (process.env.ALLOW_DEV_RESET !== "true") { return new Response( JSON.stringify({ error: "database reset is disabled in this environment", code: "RESET_DISABLED", }), { status: 403, headers: JSON_HEADERS }, ); } const gate = await gateOrUser("admin.settings"); if (gate instanceof Response) return gate; try { await resetAndSeed(); return new Response(JSON.stringify({ ok: true }), { status: 200, headers: JSON_HEADERS, }); } catch (e) { const message = e instanceof Error ? e.message : "reset failed"; return new Response(JSON.stringify({ error: message }), { status: 500, headers: JSON_HEADERS, }); } };