broke: a private money app that runs on your own accounts and your own AI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f550865e93
359 files changed
+34290
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { migrate } from "@/lib/migrate";
|
||||
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.
|
||||
export async function GET(request: Request) {
|
||||
const url = new URL(request.url);
|
||||
const back = (code: string) => NextResponse.redirect(new URL(`/setup?db=${code}`, url));
|
||||
const code = url.searchParams.get("code");
|
||||
if (!code) return back("cancelled");
|
||||
try {
|
||||
await finishConnect(code, url.searchParams.get("state"));
|
||||
} catch (e) {
|
||||
console.error("[broke] supabase callback:", e instanceof Error ? e.message : e);
|
||||
return back(e instanceof Error && /didn't start/.test(e.message) ? "elsewhere" : "rejected");
|
||||
}
|
||||
const r = await migrate();
|
||||
return back(r.error ? "update-failed" : r.applied.length ? "updated" : "current");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { currentEnv, setupAccess } from "@/lib/setup";
|
||||
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. 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 });
|
||||
const ref = refFromUrl(currentEnv().NEXT_PUBLIC_SUPABASE_URL);
|
||||
if (!ref) return NextResponse.json({ error: "Add your Supabase Project URL first." }, { status: 400 });
|
||||
try {
|
||||
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);
|
||||
return NextResponse.json({ error: "Couldn't reach Supabase. Try again in a moment." }, { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user