import type { APIRoute } from 'astro';
import { deleteSession, SESSION_COOKIE } from '../../../lib/auth';

export const prerender = false;

export const POST: APIRoute = async ({ cookies }) => {
  const sessionId = cookies.get(SESSION_COOKIE)?.value;
  if (sessionId) {
    deleteSession(sessionId);
    cookies.delete(SESSION_COOKIE, { path: '/' });
  }

  return new Response(null, { status: 303, headers: { Location: '/admin/login' } });
};
