Lumen & Gesso / website · lumengesso.com / app / api / admin / pinterest / disconnect / route.ts
| 1 | import { NextResponse } from 'next/server'; |
| 2 | import { getCustomerUser } from '@/app/lib/lumen-auth'; |
| 3 | import { isAdmin } from '@/app/lib/admin'; |
| 4 | import { clearRefreshToken } from '@/app/lib/pinterest'; |
| 5 | |
| 6 | export const runtime = 'nodejs'; |
| 7 | export const dynamic = 'force-dynamic'; |
| 8 | |
| 9 | // Admin-gated. Wipes the saved Pinterest refresh token from the integrations |
| 10 | // table. The legacy PINTEREST_REFRESH_TOKEN env fallback is NOT cleared |
| 11 | // (we can't unset env at runtime); the UI surfaces that caveat. |
| 12 | export async function POST() { |
| 13 | const user = await getCustomerUser(); |
| 14 | if (!user || !isAdmin(user.email)) { |
| 15 | return NextResponse.json({ error: 'forbidden' }, { status: 403 }); |
| 16 | } |
| 17 | |
| 18 | try { |
| 19 | await clearRefreshToken(); |
| 20 | console.log(`[pinterest/disconnect] ${user.email} cleared the refresh token`); |
| 21 | return NextResponse.json({ ok: true }); |
| 22 | } catch (e) { |
| 23 | const msg = e instanceof Error ? e.message : 'disconnect failed'; |
| 24 | return NextResponse.json({ error: msg }, { status: 500 }); |
| 25 | } |
| 26 | } |