import { NextResponse } from 'next/server'; import { getCustomerUser } from '@/app/lib/lumen-auth'; import { isAdmin } from '@/app/lib/admin'; import { clearRefreshToken } from '@/app/lib/pinterest'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; // Admin-gated. Wipes the saved Pinterest refresh token from the integrations // table. The legacy PINTEREST_REFRESH_TOKEN env fallback is NOT cleared // (we can't unset env at runtime); the UI surfaces that caveat. export async function POST() { const user = await getCustomerUser(); if (!user || !isAdmin(user.email)) { return NextResponse.json({ error: 'forbidden' }, { status: 403 }); } try { await clearRefreshToken(); console.log(`[pinterest/disconnect] ${user.email} cleared the refresh token`); return NextResponse.json({ ok: true }); } catch (e) { const msg = e instanceof Error ? e.message : 'disconnect failed'; return NextResponse.json({ error: msg }, { status: 500 }); } }