import { NextRequest, NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/pages/api/auth/[...nextauth]'; import { unsubscribeFromPush } from '@/lib/push-notifications'; export async function POST(request: NextRequest) { try { const session = await getServerSession(authOptions); if (!session?.user?.id) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const { endpoint } = await request.json(); if (!endpoint) { return NextResponse.json( { error: 'Endpoint required' }, { status: 400 } ); } await unsubscribeFromPush(session.user.id, endpoint); return NextResponse.json({ success: true }); } catch (error) { console.error('Failed to unsubscribe from push:', error); return NextResponse.json( { error: 'Failed to unsubscribe from push notifications' }, { status: 500 } ); } }