import { NextResponse } from "next/server";
import { getSessionTokenFromCookies, revokeSession } from "@/lib/server/auth";

export const runtime = "nodejs";

const SESSION_COOKIE_NAME = "gantt_session";

export async function POST() {
  try {
    const token = await getSessionTokenFromCookies();
    if (token) await revokeSession(token);
    
    // Clear cookie on response for Vercel compatibility
    const response = NextResponse.json({ success: true });
    response.cookies.set(SESSION_COOKIE_NAME, "", {
      httpOnly: true,
      sameSite: "lax",
      secure: process.env.NODE_ENV === "production",
      path: "/",
      maxAge: 0,
    });
    
    return response;
  } catch {
    return NextResponse.json({ error: "Logout failed" }, { status: 500 });
  }
}
