Use a different Supabase organization: sign in again from the project picker

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-09 12:03:02 -06:00
1 parent f674cc7baf
commit 961958685c
3 files changed
+13 -6

No files matched your search

+2 -1
View File
@@ -11,7 +11,8 @@ export async function POST(request: Request) {
// No project yet: sign in to the whole account, and broke picks (or makes) the project after. // 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); const ref = refFromUrl(currentEnv().NEXT_PUBLIC_SUPABASE_URL);
try { try {
const url = await startConnect(ref, `http://${host}/api/setup/supabase/callback`); const { fresh } = (await request.json().catch(() => ({}))) as { fresh?: boolean };
const url = await startConnect(fresh ? undefined : ref, `http://${host}/api/setup/supabase/callback`, !!fresh);
return NextResponse.json(url ? { url } : { connected: true }); return NextResponse.json(url ? { url } : { connected: true });
} catch (e) { } catch (e) {
console.error("[broke] supabase connect:", e instanceof Error ? e.message : e); console.error("[broke] supabase connect:", e instanceof Error ? e.message : e);
+8 -4
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. // One click: Supabase's own sign-in page, then back to /setup with the tables created.
export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void; onFail?: () => void }) { export function ConnectSupabaseButton({ onDone, onFail, fresh = false, label = "Connect Supabase", quiet = false }: { onDone: () => void; onFail?: () => void; fresh?: boolean; label?: string; quiet?: boolean }) {
const [busy, setBusy] = useState(false); const [busy, setBusy] = useState(false);
const [msg, setMsg] = useState(""); const [msg, setMsg] = useState("");
return ( return (
<div className="flex flex-wrap items-center gap-3"> <div className="flex flex-wrap items-center gap-3">
<button <button
className="btn-primary" className={quiet ? "btn" : "btn-primary"}
disabled={busy} disabled={busy}
onClick={async () => { onClick={async () => {
setBusy(true); setBusy(true);
setMsg(""); setMsg("");
// Supabase opens in its own tab, so broke stays put. Opened now, while the click still counts, or it's blocked. // 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 tab = window.open("", "_blank");
const res = await fetch("/api/setup/supabase/connect", { method: "POST" }); const res = await fetch("/api/setup/supabase/connect", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ fresh }) });
const body = await res.json().catch(() => ({})); const body = await res.json().catch(() => ({}));
if (body.url) { if (body.url) {
if (tab) tab.location.href = body.url; if (tab) tab.location.href = body.url;
@@ -201,7 +201,7 @@ export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void;
onDone(); onDone();
}} }}
> >
{busy ? "Opening Supabase..." : "Connect Supabase"} {busy ? "Opening Supabase..." : label}
</button> </button>
{msg && <span className="text-sm text-bad">{msg}</span>} {msg && <span className="text-sm text-bad">{msg}</span>}
</div> </div>
@@ -245,6 +245,10 @@ export function ProjectPicker({ onDone }: { onDone: () => void }) {
{busy === "new" ? "Making your project… about a minute" : "Make a new free project called broke"} {busy === "new" ? "Making your project… about a minute" : "Make a new free project called broke"}
</button> </button>
{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">
<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>
</div>
</div> </div>
); );
} }
+3 -1
View File
@@ -63,7 +63,9 @@ export const mcpConnected = (ref?: string) => {
/** Starts the sign-in. Returns the Supabase approval page to send the browser to, or null if already signed in. */ /** Starts the sign-in. Returns the Supabase approval page to send the browser to, or null if already signed in. */
// ref undefined: sign in to the whole account, so broke can list projects and fill in the URL and public key itself. // ref undefined: sign in to the whole account, so broke can list projects and fill in the URL and public key itself.
export async function startConnect(ref: string | undefined, redirect: string): Promise<string | null> { export async function startConnect(ref: string | undefined, redirect: string, fresh = false): Promise<string | null> {
// fresh: forget this sign-in, so Supabase asks again (and the person can pick a different organization).
if (fresh) save({ client: undefined, tokens: undefined, ref: undefined, all: undefined });
const s = load(); const s = load();
const all = !ref; const all = !ref;
// A new project, a change between one project and the whole account, or a new callback address needs fresh tokens. // A new project, a change between one project and the whole account, or a new callback address needs fresh tokens.