File size: 632 Bytes
c2bb873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { NextResponse } from "next/server";
import MY_TOKEN_KEY from "@/lib/get-cookie-name";

export async function POST() {
  const cookieName = MY_TOKEN_KEY();
  const isProduction = process.env.NODE_ENV === "production";
  
  const response = NextResponse.json(
    { message: "Logged out successfully" },
    { status: 200 }
  );
  
  // Clear the HTTP-only cookie
  const cookieOptions = [
    `${cookieName}=`,
    "Max-Age=0",
    "Path=/",
    "HttpOnly",
    ...(isProduction ? ["Secure", "SameSite=None"] : ["SameSite=Lax"])
  ].join("; ");
  
  response.headers.set("Set-Cookie", cookieOptions);
  
  return response;
}