Branchwell

Lumen & Gesso / website · lumengesso.com / app / api / admin / pinterest / boards / route.ts

1import { NextResponse } from 'next/server';
2import { getCustomerUser } from '@/app/lib/lumen-auth';
3import { isAdmin } from '@/app/lib/admin';
4import { listBoards } from '@/app/lib/pinterest';
5
6export const runtime = 'nodejs';
7export 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.
11export 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}