// app/api/_lib/auth.ts import { getUserBearerFromRequest } from "@/lib/directus"; export function requireBearer(req: Request): string { const bearer = getUserBearerFromRequest(req); if (!bearer) { const err: any = new Error("UNAUTHENTICATED"); err.status = 401; throw err; } return bearer; } export function jsonError(e: any, fallback = 500) { const status = e?.status ?? fallback; const body = { error: e?.message || "ERROR", detail: e?.detail ?? String(e) }; return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } }); }