import { NextRequest, NextResponse } from 'next/server';
import { clearSession, getSession } from '@/lib/auth';
import { query } from '@/lib/db';
export const runtime = 'nodejs';
export async function POST(req: NextRequest) {
  const user = await getSession();
  if (user) await query('INSERT INTO audit_logs (actor_id, entity_table, entity_id, action, ip_address) VALUES (?, \'users\', ?, \'LOGOUT\', ?)', [user.id, user.id, req.headers.get('x-forwarded-for')?.split(',')[0] || null]);
  await clearSession();
  return NextResponse.json({ ok: true });
}
