import { NextResponse } from "next/server";

function expireCookie(res: NextResponse, name: string, secure: boolean) {
  res.cookies.set({
    name,
    value: "",
    path: "/",
    httpOnly: true,
    sameSite: "lax",
    secure,
    maxAge: 0,
  });
}

export async function GET(req: Request) {
  const url = new URL(req.url);
  const redirectTo = new URL("/admin/login", url);

  const res = NextResponse.redirect(redirectTo);

  // Clear both secure and non-secure cookie variants.
  expireCookie(res, "next-auth.session-token", false);
  expireCookie(res, "__Secure-next-auth.session-token", true);

  expireCookie(res, "next-auth.csrf-token", false);
  expireCookie(res, "__Host-next-auth.csrf-token", true);

  expireCookie(res, "next-auth.callback-url", false);
  expireCookie(res, "__Secure-next-auth.callback-url", true);

  return res;
}




