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:
1 parent
f674cc7baf
commit
961958685c
3 files changed
+13
-6
No files matched your search
@@ -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.
|
||||
const ref = refFromUrl(currentEnv().NEXT_PUBLIC_SUPABASE_URL);
|
||||
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 });
|
||||
} catch (e) {
|
||||
console.error("[broke] supabase connect:", e instanceof Error ? e.message : e);
|
||||
|
||||
@@ -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 }: { 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 [msg, setMsg] = useState("");
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
className="btn-primary"
|
||||
className={quiet ? "btn" : "btn-primary"}
|
||||
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" });
|
||||
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(() => ({}));
|
||||
if (body.url) {
|
||||
if (tab) tab.location.href = body.url;
|
||||
@@ -201,7 +201,7 @@ export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void;
|
||||
onDone();
|
||||
}}
|
||||
>
|
||||
{busy ? "Opening Supabase..." : "Connect Supabase"}
|
||||
{busy ? "Opening Supabase..." : label}
|
||||
</button>
|
||||
{msg && <span className="text-sm text-bad">{msg}</span>}
|
||||
</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"}
|
||||
</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, so you can choose the organization that has the project you want.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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. */
|
||||
// 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 all = !ref;
|
||||
// A new project, a change between one project and the whole account, or a new callback address needs fresh tokens.
|
||||
|
||||
Reference in new issue
Block a user