Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { NextResponse } from 'next/server' import { withAuth } from '@/lib/auth/withAuth' import { syncCheckoutSession } from '@/lib/billing-sync' /** * POST /api/billing/checkout/verify * * Verify a completed Stripe Checkout session and sync the subscription * to the local database. Called on the success redirect so the app * doesn't depend solely on webhooks (which don't reach localhost). * * Body: { sessionId: string } */ export const POST = withAuth( async (request) => { const { sessionId } = await request.json() if (!sessionId || typeof sessionId !== 'string') { return NextResponse.json({ error: 'Missing sessionId' }, { status: 400 }) } try { await syncCheckoutSession(sessionId) return NextResponse.json({ synced: true }) } catch (err) { console.error('[billing/checkout/verify] Failed to sync:', err) return NextResponse.json({ error: 'Failed to verify session' }, { status: 500 }) } }, { role: 'user' } ) |