diff --git a/src/app/api/requests/route.ts b/src/app/api/requests/route.ts index 952e3fa..930b40a 100644 --- a/src/app/api/requests/route.ts +++ b/src/app/api/requests/route.ts @@ -1,7 +1,18 @@ import { NextResponse } from "next/server"; +import { auth } from "@/auth"; import { createRequest, listRequests, validateCreateRequestInput } from "@/lib/requests"; +// middleware.ts's config.matcher deliberately excludes /api from route +// protection (see its comment) — API routes verify the session themselves, +// here, rather than relying on middleware alone. Permission model is flat +// (CLAUDE.md): this only checks "logged in or not", no role/permission +// check. export async function POST(request: Request): Promise { + const session = await auth(); + if (!session) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + let body: unknown; try { body = await request.json(); @@ -25,6 +36,11 @@ export async function POST(request: Request): Promise { } export async function GET(): Promise { + const session = await auth(); + if (!session) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + const requests = await listRequests(); return NextResponse.json(requests, { status: 200 }); }