export const prerender = false;

import type { APIRoute } from 'astro';
import { env } from 'cloudflare:workers';
import { clearSession, type SessionEnv } from '../../../lib/session.js';
import { type DbEnv } from '../../../lib/db.js';
import { type StorefrontLimiterEnv } from '../../../lib/rate-limit.js';
import { type AuthEnv } from '../../../lib/auth-engine.js';

export const POST: APIRoute = async ({ cookies, redirect }) => {
  const cfEnv = env as (AuthEnv & SessionEnv & DbEnv & StorefrontLimiterEnv) | undefined;
  if (cfEnv?.SESSION) {
    await clearSession(cfEnv, cookies);
  }
  return redirect('/', 302);
};
