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

export const runtime = "nodejs";

export async function POST() {
  try {
    const token = await getSessionTokenFromCookies();
    if (token) await revokeSession(token);
    await clearSessionCookie();
    return NextResponse.json({ success: true });
  } catch {
    return NextResponse.json({ error: "Logout failed" }, { status: 500 });
  }
}
