import { NextResponse } from 'next/server';

const COOKIE_NAMES = [
  'authjs.session-token',
  'authjs.csrf-token',
  'authjs.callback-url',
  '__Secure-authjs.session-token',
  '__Secure-authjs.callback-url',
  '__Host-authjs.csrf-token',
  'next-auth.session-token',
  'next-auth.csrf-token',
  'next-auth.callback-url',
  '__Secure-next-auth.session-token',
  '__Secure-next-auth.callback-url',
  '__Host-next-auth.csrf-token',
];

export async function POST() {
  const response = NextResponse.json({ ok: true });

  for (const name of COOKIE_NAMES) {
    // Set with secure attributes (production)
    response.cookies.set({
      name,
      value: '',
      path: '/',
      maxAge: 0,
      expires: new Date(0),
      httpOnly: true,
      secure: true,
      sameSite: 'lax',
    });
  }

  // Prevent caching of this response
  response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
  response.headers.set('Pragma', 'no-cache');
  response.headers.set('Expires', '0');

  return response;
}

export async function GET() {
  return POST();
}
