import {
  clearSessionCookie,
  deleteSession,
  requestUsesHttps,
  sessionCookieFromHeader,
} from "../../../../lib/user-auth";

export async function POST(request: Request) {
  const token = sessionCookieFromHeader(request.headers.get("cookie"));
  await deleteSession(token);
  const secure = requestUsesHttps(request);
  return Response.json(
    { loggedOut: true },
    { headers: { "Set-Cookie": clearSessionCookie(secure) } },
  );
}
