import { redirect } from 'next/navigation'; import { getCustomerUser } from '@/app/lib/lumen-auth'; import { isAdmin } from '@/app/lib/admin'; import { listBoards, pinterestSetupStatus, callbackUrl, type PinterestBoard } from '@/app/lib/pinterest'; import { AdminNav } from '../AdminNav'; import { DisconnectButton } from './DisconnectButton'; export const dynamic = 'force-dynamic'; // Admin · Pinterest setup + connection status. Renders one of three states // depending on which env vars are set: // 1. Client creds missing → instructions for creating the Pinterest app // 2. Client creds set, refresh token missing → "Connect Pinterest" CTA // 3. Fully wired → boards listed + sanity check passes export default async function AdminPinterestPage() { const user = await getCustomerUser(); if (!user) redirect('/login?next=/admin/pinterest'); if (!isAdmin(user.email)) redirect('/orders'); const status = await pinterestSetupStatus(); let boards: PinterestBoard[] | null = null; let boardsError: string | null = null; if (status.ready) { try { boards = await listBoards(); } catch (e) { boardsError = e instanceof Error ? e.message : 'failed to list boards'; } } return (

Admin · Pinterest

{status.mode === 'access-token' && (

Wired via PINTEREST_ACCESS_TOKEN. Skipping OAuth — Pinterest’s dev-console tokens are long-lived but not refreshable; rotate by generating a new one in the dev portal and re-pasting into env.

)} {status.mode === 'unconfigured' && !status.hasClient && (
  1. Go to developers.pinterest.com/apps and click Connect app.
  2. Name it "Lumen & Gesso", upload the logo, and submit.
  3. Open the app, add a Redirect URI exactly equal to:
    {callbackUrl()}
    (and the production one — https://www.lumengesso.com/api/admin/pinterest/callback — if different).
  4. Copy the App ID and App secret key.
  5. Paste into your env and restart:
    PINTEREST_CLIENT_ID=…
    PINTEREST_CLIENT_SECRET=…
)} {status.mode !== 'access-token' && status.hasClient && !status.hasRefreshToken && (

Click below to start the OAuth handshake. Pinterest will ask you to grant pins:read, pins:write, and boards:read — accept, and you'll be redirected back here with a refresh token to copy into env.

Connect Pinterest →

Callback URL Pinterest will hit: {callbackUrl()}

)} {status.ready && ( {boardsError ? (

Couldn't list boards: {boardsError}

) : ( <>

Found {boards?.length ?? 0} board{boards?.length === 1 ? '' : 's'}. Use the /admin/images page to pin individual portraits.

{boards && boards.length > 0 && (
    {boards.map((b) => (
  • {b.name}{' '} (id {b.id}{b.privacy ? `, ${b.privacy}` : ''})
  • ))}
)}

Need to re-auth? Reconnect (refresh tokens last ~1 year).

{status.mode === 'oauth' && ( )} )}
)}
); } function StatusRow({ label, ok, note }: { label: string; ok: boolean; note?: string }) { return (
{label} {note && ( {note} )} {ok ? 'set ✓' : 'not set'}
); } function Step({ n, title, children }: { n: number; title: string; children: React.ReactNode }) { return (
Step {n}

{title}

{children}
); } const pre: React.CSSProperties = { background: '#1d1a17', color: '#f3eadd', padding: '10px 14px', borderRadius: 8, fontSize: 12.5, lineHeight: 1.45, overflowX: 'auto', margin: '6px 0', }; const cta: React.CSSProperties = { display: 'inline-block', padding: '9px 16px', borderRadius: 8, background: 'var(--ink)', color: 'var(--cream)', textDecoration: 'none', fontSize: 14, fontWeight: 600, };