import { supabase } from '@/lib/supabase'; import type { APIRoute } from 'astro'; export const POST: APIRoute = async ({ request }) => { const headers = { 'Content-Type': 'application/json' }; try { const { email, userId, signatureId } = await request.json(); if (!email || !userId || !signatureId) { return new Response( JSON.stringify({ success: false, message: 'Email or signature data is missing.', }), { status: 400, headers } ); } const { error } = await supabase .from('unesco_petition_signatures') .delete() .eq('id', signatureId) .eq('email', email) .eq('workos_user_id', userId); if (error) { return new Response( JSON.stringify({ success: false, message: "Database says it was unable to delete your record. Please text me on Instagram (@palacejunwon) and I'll manually help you then fix the database problem!", }), { status: 500, headers } ); } return new Response( JSON.stringify({ success: true, message: 'Your signature was deleted successfully!' }), { status: 200, headers } ); } catch (error) { return new Response( JSON.stringify({ success: false, message: "Database says it was unable to delete your record. Please text me on Instagram (@palacejunwon) and I'll manually help you then fix the database problem.", }), { status: 500, headers } ); } };