057da00fd2
Uniform stock management for healthcare linen rooms: the coordinator app, the phone counter and the staff app, for your own server. Built from e2d6d42 on 2026-09-13. Licensed under the Functional Source License (FSL-1.1-ALv2).
23 lines
958 B
TypeScript
23 lines
958 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { clearSessionCookie, currentUser } from "@/lib/session";
|
|
import { sameOriginJson } from "@/lib/csrf";
|
|
import { clientIp } from "@/lib/ratelimit";
|
|
import { recordAuthEvent } from "@/lib/audit";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const csrf = sameOriginJson(req, false); if (csrf) return NextResponse.json({ error: csrf }, { status: 403 });
|
|
// Read the session before dropping it, so the trail can say who left. An unauthenticated call
|
|
// still clears the cookie and still answers ok — signing out must never fail.
|
|
const user = await currentUser();
|
|
await clearSessionCookie();
|
|
if (user) {
|
|
recordAuthEvent(
|
|
{ facilityId: user.facilityId, userId: user.id, userName: `${user.first} ${user.last}`.trim() || user.email },
|
|
"auth:signout", clientIp(req.headers),
|
|
);
|
|
}
|
|
return NextResponse.json({ ok: true });
|
|
}
|