import { NextRequest, NextResponse } from "next/server"; import { supabase } from "@/lib/supabase"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; export async function POST(request: NextRequest) { try { const { userId, endpoint } = await request.json(); if (!userId || !endpoint) { return NextResponse.json({ error: "User ID and endpoint are required" }, { status: 400 }); } const { error } = await supabase .from("push_subscriptions") .delete() .eq("user_id", userId) .eq("endpoint", endpoint); if (error) { console.error("Delete subscription error:", error); return NextResponse.json({ error: "Failed to unsubscribe" }, { status: 500 }); } return NextResponse.json({ success: true, message: "Unsubscribed from push notifications" }); } catch (error: any) { console.error("Unsubscribe from push notifications error:", error); return NextResponse.json({ error: error.message || "Internal server error" }, { status: 500 }); } }