From cb56fd11a0bfc1007751a93150e8341ab95a2db9 Mon Sep 17 00:00:00 2001 From: minimus7 Date: Mon, 9 Nov 2026 12:11:40 -0600 Subject: [PATCH] Project picker names the connected Supabase organization, and says to change it on the approval page Co-Authored-By: Claude Opus 5.5 --- src/app/api/setup/supabase/project/route.ts | 5 +++-- src/app/setup/SetupActions.tsx | 7 +++++-- src/lib/supabase-mcp.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/api/setup/supabase/project/route.ts b/src/app/api/setup/supabase/project/route.ts index f3f946b..082343e 100644 --- a/src/app/api/setup/supabase/project/route.ts +++ b/src/app/api/setup/supabase/project/route.ts @@ -1,7 +1,7 @@ import { NextResponse } from "next/server"; import { sameOrigin, setupAccess } from "@/lib/setup"; import { fillFrom } from "@/lib/supabase-fill"; -import { accountConnected, createProject, listProjects } from "@/lib/supabase-mcp"; +import { accountConnected, createProject, listOrgs, listProjects } from "@/lib/supabase-mcp"; const LOOPBACK = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/; const local = async (request: Request) => LOOPBACK.test(request.headers.get("host") ?? "") && (await setupAccess()).allowed && accountConnected(); @@ -11,7 +11,8 @@ const local = async (request: Request) => LOOPBACK.test(request.headers.get("hos export async function GET(request: Request) { if (!(await local(request))) return NextResponse.json({ error: "Only on this computer, after Connect Supabase." }, { status: 403 }); try { - return NextResponse.json({ projects: await listProjects() }); + const [projects, orgs] = await Promise.all([listProjects(), listOrgs()]); + return NextResponse.json({ projects, orgs: orgs.map((o) => o.name) }); } catch (e) { console.error("[broke] supabase projects:", e instanceof Error ? e.message : e); return NextResponse.json({ error: "Couldn't list your Supabase projects. Press Connect Supabase again." }, { status: 502 }); diff --git a/src/app/setup/SetupActions.tsx b/src/app/setup/SetupActions.tsx index 516ae52..30bc30a 100644 --- a/src/app/setup/SetupActions.tsx +++ b/src/app/setup/SetupActions.tsx @@ -214,10 +214,11 @@ type Project = { id: string; name: string; region?: string; status?: string }; // public key and creates the tables (POST /api/setup/supabase/project). export function ProjectPicker({ onDone }: { onDone: () => void }) { const [projects, setProjects] = useState(null); + const [orgs, setOrgs] = useState([]); const [busy, setBusy] = useState(null); const [msg, setMsg] = useState(""); useEffect(() => { - fetch("/api/setup/supabase/project").then((r) => r.json()).then((b: { projects?: Project[]; error?: string }) => (b.error ? setMsg(b.error) : setProjects(b.projects ?? []))).catch(() => setMsg("Couldn't reach broke. Is it still running?")); + fetch("/api/setup/supabase/project").then((r) => r.json()).then((b: { projects?: Project[]; orgs?: string[]; error?: string }) => { if (b.error) setMsg(b.error); else { setProjects(b.projects ?? []); setOrgs(b.orgs ?? []); } }).catch(() => setMsg("Couldn't reach broke. Is it still running?")); }, []); async function use(body: { ref?: string; create?: boolean }, label: string) { setBusy(label); @@ -229,8 +230,10 @@ export function ProjectPicker({ onDone }: { onDone: () => void }) { else setMsg(b?.error ?? "That didn't work. Try again."); } if (!projects && !msg) return

Finding your projects…

; + const where = orgs.length ? `Supabase organization${orgs.length > 1 ? "s" : ""} ${orgs.map((o) => `“${o}”`).join(", ")}` : "your Supabase account"; return (
+

{projects?.length ? `Projects in ${where}:` : `Connected to ${where}, which has no projects yet.`}

{!!projects?.length && (
    {projects.map((p) => ( @@ -247,7 +250,7 @@ export function ProjectPicker({ onDone }: { onDone: () => void }) { {msg &&

    {msg}

    }
    -

    Signs in to Supabase again, so you can choose the organization that has the project you want.

    +

    Signs in to Supabase again. On Supabase's approval page, change the organization to the one that has the project you want before you approve.

); diff --git a/src/lib/supabase-mcp.ts b/src/lib/supabase-mcp.ts index efdd966..86a8fca 100644 --- a/src/lib/supabase-mcp.ts +++ b/src/lib/supabase-mcp.ts @@ -151,6 +151,16 @@ export async function listProjects(): Promise { } } +/** The organizations this sign-in was approved for (Supabase's approval page picks them). */ +export async function listOrgs(): Promise<{ id: string; name: string }[]> { + const client = await connectClient(load()); + try { + return listOf<{ id: string; name: string }>(unwrap(await call(client, "list_organizations", {})), "organizations").map((o) => ({ id: o.id, name: o.name })); + } finally { + await client.close().catch(() => {}); + } +} + /** Picks a project: its address and publishable key, read through the sign-in. Saves the choice for the migrations. */ export async function projectKeys(ref: string) { const s = load();