Supabase sign-in that expired: say so and offer Connect Supabase again; ask for projects one at a time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-09 12:12:45 -06:00
1 parent cb56fd11a0
commit e7c5c8df69
2 files changed
+15 -4

No files matched your search

+5 -3
View File
@@ -11,11 +11,13 @@ 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 {
const [projects, orgs] = await Promise.all([listProjects(), listOrgs()]);
// 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: "Couldn't list your Supabase projects. Press Connect Supabase again." }, { status: 502 });
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 });
}
}
@@ -28,6 +30,6 @@ export async function POST(request: Request) {
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/.test(e.message) ? e.message : "Supabase didn't answer. Try again in a moment." }, { status: 502 });
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 });
}
}
+10 -1
View File
@@ -110,7 +110,16 @@ export async function mcpSession(): Promise<{ exec: Exec; close: () => Promise<v
async function connectClient(s: Saved) {
const client = new Client({ name: "broke", version: "1.0.0" });
await client.connect(new StreamableHTTPClientTransport(new URL(urlOf(s)), { authProvider: provider(s.redirect!) }));
try {
await client.connect(new StreamableHTTPClientTransport(new URL(urlOf(s)), { authProvider: provider(s.redirect!) }));
} catch (e) {
// The sign-in expired and couldn't be renewed: forget it, so the page offers Connect Supabase again.
if (/unauthori[sz]ed|invalid_grant|401/i.test(e instanceof Error ? e.message : String(e))) {
save({ tokens: undefined });
throw new Error("Your Supabase sign-in expired. Press Connect Supabase again.");
}
throw e;
}
return client;
}