Project picker names the connected Supabase organization, and says to change it on the approval page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7df0dba8f
commit
cb56fd11a0
3 files changed
+18
-4
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { sameOrigin, setupAccess } from "@/lib/setup";
|
import { sameOrigin, setupAccess } from "@/lib/setup";
|
||||||
import { fillFrom } from "@/lib/supabase-fill";
|
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 LOOPBACK = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/;
|
||||||
const local = async (request: Request) => LOOPBACK.test(request.headers.get("host") ?? "") && (await setupAccess()).allowed && accountConnected();
|
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) {
|
export async function GET(request: Request) {
|
||||||
if (!(await local(request))) return NextResponse.json({ error: "Only on this computer, after Connect Supabase." }, { status: 403 });
|
if (!(await local(request))) return NextResponse.json({ error: "Only on this computer, after Connect Supabase." }, { status: 403 });
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
console.error("[broke] supabase projects:", e instanceof Error ? e.message : 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 });
|
return NextResponse.json({ error: "Couldn't list your Supabase projects. Press Connect Supabase again." }, { status: 502 });
|
||||||
|
|||||||
@@ -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).
|
// public key and creates the tables (POST /api/setup/supabase/project).
|
||||||
export function ProjectPicker({ onDone }: { onDone: () => void }) {
|
export function ProjectPicker({ onDone }: { onDone: () => void }) {
|
||||||
const [projects, setProjects] = useState<Project[] | null>(null);
|
const [projects, setProjects] = useState<Project[] | null>(null);
|
||||||
|
const [orgs, setOrgs] = useState<string[]>([]);
|
||||||
const [busy, setBusy] = useState<string | null>(null);
|
const [busy, setBusy] = useState<string | null>(null);
|
||||||
const [msg, setMsg] = useState("");
|
const [msg, setMsg] = useState("");
|
||||||
useEffect(() => {
|
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) {
|
async function use(body: { ref?: string; create?: boolean }, label: string) {
|
||||||
setBusy(label);
|
setBusy(label);
|
||||||
@@ -229,8 +230,10 @@ export function ProjectPicker({ onDone }: { onDone: () => void }) {
|
|||||||
else setMsg(b?.error ?? "That didn't work. Try again.");
|
else setMsg(b?.error ?? "That didn't work. Try again.");
|
||||||
}
|
}
|
||||||
if (!projects && !msg) return <p className="text-sm text-muted">Finding your projects…</p>;
|
if (!projects && !msg) return <p className="text-sm text-muted">Finding your projects…</p>;
|
||||||
|
const where = orgs.length ? `Supabase organization${orgs.length > 1 ? "s" : ""} ${orgs.map((o) => `“${o}”`).join(", ")}` : "your Supabase account";
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
|
<p className="text-sm text-muted">{projects?.length ? `Projects in ${where}:` : `Connected to ${where}, which has no projects yet.`}</p>
|
||||||
{!!projects?.length && (
|
{!!projects?.length && (
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-2">
|
||||||
{projects.map((p) => (
|
{projects.map((p) => (
|
||||||
@@ -247,7 +250,7 @@ export function ProjectPicker({ onDone }: { onDone: () => void }) {
|
|||||||
{msg && <p className="text-sm text-bad">{msg}</p>}
|
{msg && <p className="text-sm text-bad">{msg}</p>}
|
||||||
<div className="pt-1 space-y-1">
|
<div className="pt-1 space-y-1">
|
||||||
<ConnectSupabaseButton onDone={onDone} fresh quiet label="Use a different Supabase organization" />
|
<ConnectSupabaseButton onDone={onDone} fresh quiet label="Use a different Supabase organization" />
|
||||||
<p className="text-xs text-muted">Signs in to Supabase again, so you can choose the organization that has the project you want.</p>
|
<p className="text-xs text-muted">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.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -151,6 +151,16 @@ export async function listProjects(): Promise<Project[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 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. */
|
/** 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) {
|
export async function projectKeys(ref: string) {
|
||||||
const s = load();
|
const s = load();
|
||||||
|
|||||||
Reference in new issue
Block a user