import { NextResponse } from "next/server"; // Server-side proxy to be-crm's founder-access by-session lookup. The /thanks page // (post-Stripe) polls this with the checkout session_id until the webhook has // fulfilled the purchase and a founder token exists, then redirects to the // prefilled register page. `pending` means "poll again shortly". export const runtime = "nodejs"; const CRM_BASE_URL = (process.env.CRM_BASE_URL ?? "https://crm.lynkedup.cloud").replace(/\/$/, ""); export async function GET(request: Request) { const sessionId = new URL(request.url).searchParams.get("session_id") ?? ""; if (!sessionId || sessionId.length > 256) { return NextResponse.json({ ok: false, status: "pending" }, { status: 400 }); } try { const res = await fetch(`${CRM_BASE_URL}/public/founder-access/by-session?session_id=${encodeURIComponent(sessionId)}`, { headers: { Accept: "application/json" }, cache: "no-store", }); if (!res.ok) return NextResponse.json({ ok: false, status: "pending" }, { status: 502 }); return NextResponse.json(await res.json()); } catch { return NextResponse.json({ ok: false, status: "pending" }, { status: 502 }); } }