Lumen & Gesso / website · lumengesso.com / app / api / admin / pinterest / boards / 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 { listBoards } from '@/app/lib/pinterest'; |
| 5 | |
| 6 | export const runtime = 'nodejs'; |
| 7 | export const dynamic = 'force-dynamic'; |
| 8 | |
| 9 | // Admin-gated. Returns the studio's Pinterest boards. Used by the CdnBrowser |
| 10 | // pin modal to populate the board dropdown. |
| 11 | export async function GET() { |
| 12 | const user = await getCustomerUser(); |
| 13 | if (!user || !isAdmin(user.email)) { |
| 14 | return NextResponse.json({ error: 'forbidden' }, { status: 403 }); |
| 15 | } |
| 16 | try { |
| 17 | const boards = await listBoards(); |
| 18 | return NextResponse.json({ boards }); |
| 19 | } catch (e) { |
| 20 | const msg = e instanceof Error ? e.message : 'list-boards failed'; |
| 21 | return NextResponse.json({ error: msg }, { status: 502 }); |
| 22 | } |
| 23 | } |