Back to manual Supabase setup: paste three keys, then the connection string and password

The account-wide sign-in, project picker and project creation are gone. Signing in to Supabase stays as an option on step 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-09 12:13:42 -06:00
1 parent e7c5c8df69
commit a842601665
9 files changed
+33 -301

No files matched your search

+1 -14
View File
@@ -1,8 +1,6 @@
import { NextResponse } from "next/server";
import { migrate } from "@/lib/migrate";
import { currentEnv } from "@/lib/setup";
import { accountConnected, finishConnect, listProjects } from "@/lib/supabase-mcp";
import { fillFrom } from "@/lib/supabase-fill";
import { finishConnect } from "@/lib/supabase-mcp";
// Supabase sends the browser back here after "Approve". Finish the sign-in, then bring the tables up to date.
// The result goes back as a code (DB_MESSAGES on the Setup page), never as text, so the link can't carry a message.
@@ -17,17 +15,6 @@ export async function GET(request: Request) {
console.error("[broke] supabase callback:", e instanceof Error ? e.message : e);
return back(e instanceof Error && /didn't start/.test(e.message) ? "elsewhere" : "rejected");
}
// Signed in to the whole account with no project set yet: one project is used straight away, several are picked on the page.
if (accountConnected() && !currentEnv().NEXT_PUBLIC_SUPABASE_URL?.includes(".supabase.co")) {
try {
const projects = await listProjects();
if (projects.length !== 1) return back(projects.length ? "pick" : "no-project");
return back((await fillFrom(projects[0].id)).tables ? "filled" : "filled-no-tables");
} catch (e) {
console.error("[broke] supabase fill:", e instanceof Error ? e.message : e);
return back("pick");
}
}
const r = await migrate();
return back(r.error ? "update-failed" : r.applied.length ? "updated" : "current");
}
+3 -4
View File
@@ -4,15 +4,14 @@ import { refFromUrl, startConnect } from "@/lib/supabase-mcp";
const LOOPBACK = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/;
// "Connect Supabase": returns the Supabase approval page, for this project or (before one is set) the whole account. Localhost only.
// "Connect Supabase": returns the Supabase approval page for this project. Localhost only.
export async function POST(request: Request) {
const host = request.headers.get("host") ?? "";
if (!LOOPBACK.test(host) || !(await setupAccess()).allowed) return NextResponse.json({ error: "Only on this computer." }, { status: 403 });
// No project yet: sign in to the whole account, and broke picks (or makes) the project after.
const ref = refFromUrl(currentEnv().NEXT_PUBLIC_SUPABASE_URL);
if (!ref) return NextResponse.json({ error: "Add your Supabase Project URL first." }, { status: 400 });
try {
const { fresh } = (await request.json().catch(() => ({}))) as { fresh?: boolean };
const url = await startConnect(fresh ? undefined : ref, `http://${host}/api/setup/supabase/callback`, !!fresh);
const url = await startConnect(ref, `http://${host}/api/setup/supabase/callback`);
return NextResponse.json(url ? { url } : { connected: true });
} catch (e) {
console.error("[broke] supabase connect:", e instanceof Error ? e.message : e);
@@ -1,35 +0,0 @@
import { NextResponse } from "next/server";
import { sameOrigin, setupAccess } from "@/lib/setup";
import { fillFrom } from "@/lib/supabase-fill";
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();
// After "Connect Supabase" signed in to the whole account: list its projects, or use one (or a new one). Using one writes
// its address and publishable key to .env.local and creates broke's tables through the same sign-in. Localhost only.
export async function GET(request: Request) {
if (!(await local(request))) return NextResponse.json({ error: "Only on this computer, after Connect Supabase." }, { status: 403 });
try {
// One after the other: two at once could both renew the sign-in, and the second renewal cancels the first.
const projects = await listProjects();
const orgs = await 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: e instanceof Error && /expired/.test(e.message) ? e.message : "Couldn't list your Supabase projects. Press Connect Supabase again." }, { status: 502 });
}
}
export async function POST(request: Request) {
if (!(await local(request)) || !sameOrigin(request)) return NextResponse.json({ error: "Only on this computer, after Connect Supabase." }, { status: 403 });
const { ref, create } = (await request.json().catch(() => ({}))) as { ref?: string; create?: boolean };
try {
const id = create ? await createProject() : ref && /^[a-z0-9]{20}$/.test(ref) ? ref : null;
if (!id) return NextResponse.json({ error: "Pick a project." }, { status: 400 });
return NextResponse.json(await fillFrom(id));
} catch (e) {
console.error("[broke] supabase project:", e instanceof Error ? e.message : e);
return NextResponse.json({ error: e instanceof Error && /cost money|organization|free projects|expired/.test(e.message) ? e.message : "Supabase didn't answer. Try again in a moment." }, { status: 502 });
}
}
+4 -51
View File
@@ -171,20 +171,20 @@ export function MigrateButton({ onDone }: { onDone: () => void }) {
}
// One click: Supabase's own sign-in page, then back to /setup with the tables created.
export function ConnectSupabaseButton({ onDone, onFail, fresh = false, label = "Connect Supabase", quiet = false }: { onDone: () => void; onFail?: () => void; fresh?: boolean; label?: string; quiet?: boolean }) {
export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void; onFail?: () => void }) {
const [busy, setBusy] = useState(false);
const [msg, setMsg] = useState("");
return (
<div className="flex flex-wrap items-center gap-3">
<button
className={quiet ? "btn" : "btn-primary"}
className="btn"
disabled={busy}
onClick={async () => {
setBusy(true);
setMsg("");
// Supabase opens in its own tab, so broke stays put. Opened now, while the click still counts, or it's blocked.
const tab = window.open("", "_blank");
const res = await fetch("/api/setup/supabase/connect", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ fresh }) });
const res = await fetch("/api/setup/supabase/connect", { method: "POST" });
const body = await res.json().catch(() => ({}));
if (body.url) {
if (tab) tab.location.href = body.url;
@@ -201,57 +201,10 @@ export function ConnectSupabaseButton({ onDone, onFail, fresh = false, label = "
onDone();
}}
>
{busy ? "Opening Supabase..." : label}
{busy ? "Opening Supabase..." : "Connect Supabase"}
</button>
{msg && <span className="text-sm text-bad">{msg}</span>}
</div>
);
}
type Project = { id: string; name: string; region?: string; status?: string };
// After Connect Supabase: the account's projects, or a new free one called broke. Picking fills in its address and
// public key and creates the tables (POST /api/setup/supabase/project).
export function ProjectPicker({ onDone }: { onDone: () => void }) {
const [projects, setProjects] = useState<Project[] | null>(null);
const [orgs, setOrgs] = useState<string[]>([]);
const [busy, setBusy] = useState<string | null>(null);
const [msg, setMsg] = useState("");
useEffect(() => {
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);
setMsg("");
const res = await fetch("/api/setup/supabase/project", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }).catch(() => null);
const b = (await res?.json().catch(() => ({}))) as { error?: string } | undefined;
setBusy(null);
if (res?.ok) onDone();
else setMsg(b?.error ?? "That didn't work. Try again.");
}
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 (
<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 && (
<ul className="space-y-2">
{projects.map((p) => (
<li key={p.id} className="flex items-center justify-between gap-3 rounded-xl border border-line px-4 py-3">
<span className="min-w-0"><span className="block font-medium truncate">{p.name}</span><span className="block text-xs text-muted">{p.id}{p.region ? ` · ${p.region}` : ""}</span></span>
<button className="btn shrink-0" disabled={!!busy} onClick={() => use({ ref: p.id }, p.id)}>{busy === p.id ? "Setting up…" : "Use this one"}</button>
</li>
))}
</ul>
)}
<button className={projects?.length ? "btn" : "btn-primary"} disabled={!!busy} onClick={() => use({ create: true }, "new")}>
{busy === "new" ? "Making your project… about a minute" : "Make a new free project called broke"}
</button>
{msg && <p className="text-sm text-bad">{msg}</p>}
<div className="pt-1 space-y-1">
<ConnectSupabaseButton onDone={onDone} fresh quiet label="Use a different Supabase organization" />
<p className="text-xs text-muted">Signs in to Supabase again. On Supabase&apos;s approval page, change the organization to the one that has the project you want before you approve.</p>
</div>
</div>
);
}
+11 -11
View File
@@ -5,7 +5,7 @@ import Link from "next/link";
import { useCallback, useEffect, useState } from "react";
import { Logo } from "@/components/Logo";
import type { AiRow, Part, Section, SetupStatus } from "@/lib/setup";
import { CopyCommand, KeyForm, ConnectSupabaseButton, MigrateButton, ProjectPicker } from "./SetupActions";
import { CopyCommand, KeyForm, ConnectSupabaseButton, MigrateButton } from "./SetupActions";
export function ExtLink({ href, children }: { href: string; children: React.ReactNode }) {
return (
@@ -214,16 +214,16 @@ export function Body({ s, data, signedIn, reload }: { s: Section; data: SetupSta
<>
{s.note && s.status !== "done" && s.status !== "error" && <p className="text-sm">{s.note}</p>}
{s.note && s.status === "done" && s.kind === "more" && <p className="text-sm">{s.note}</p>}
{s.action === "connect" && <ConnectSupabaseButton onDone={reload} onFail={() => setFallback(true)} />}
{s.action === "pick" && <ProjectPicker onDone={() => window.location.reload()} />}
{(s.action === "connect" || s.action === "pick") && (s.steps || s.fields) ? (
<details className="text-sm" open={fallback} onToggle={(e) => setFallback(e.currentTarget.open)}>
<summary className="cursor-pointer text-muted hover:text-ink">{s.fallback ?? "Button didn't work? Paste a connection string instead"}</summary>
<div className="pt-3 space-y-4">
<Steps steps={s.steps} />
{form}
</div>
</details>
{s.action === "connect" && (s.steps || s.fields) ? (
// Step 2: paste the connection string and password (the reliable way), or sign in to Supabase instead.
<>
<Steps steps={s.steps} />
{form}
<details className="text-sm" open={fallback} onToggle={(e) => setFallback(e.currentTarget.open)}>
<summary className="cursor-pointer text-muted hover:text-ink">Or sign in to Supabase instead of pasting</summary>
<div className="pt-3"><ConnectSupabaseButton onDone={reload} /></div>
</details>
</>
) : s.status === "done" && s.kind !== "more" && s.fields ? (
// Connected: the steps and empty boxes are noise now. They stay one click away for changing a key.
<details className="text-sm">
-4
View File
@@ -6,8 +6,4 @@ export const DB_MESSAGES: Record<string, string> = {
"update-failed": "Connected, but a database update failed. Press Update database below to see why.",
updated: "Connected. Tables updated.",
current: "Connected. Tables are up to date.",
filled: "Connected. broke filled in your project's address and public key and created its tables. One key left to paste.",
"filled-no-tables": "Connected and filled in. Creating the tables didn't finish: press Update database under step 2.",
pick: "Connected. Pick the project broke should use.",
"no-project": "Connected. This account has no projects yet: make one below.",
};