Initial commit
This commit is contained in:
23
app/api/auth/logout/route.ts
Normal file
23
app/api/auth/logout/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { SESSION_COOKIE } from "../../../../lib/auth/session";
|
||||
import { ok } from "../../../../lib/http";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
console.log("[LOGOUT] User logout");
|
||||
|
||||
const res = ok({ message: "Logged out successfully" });
|
||||
|
||||
// Clear the session cookie
|
||||
res.cookies.set(SESSION_COOKIE, "", {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/",
|
||||
maxAge: 0,
|
||||
});
|
||||
|
||||
console.log("[LOGOUT] Session cleared");
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user