Clearer database setup: what to copy where, a password box, and a fallback that opens itself

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-04 15:35:17 -06:00
1 parent febd77e105
commit c3276ab5c1
5 files changed
+49 -20

No files matched your search

+6 -2
View File
@@ -102,6 +102,7 @@ export function KeyForm({ fields, canWrite, writeNote, onSaved }: { fields: Fiel
</span>
)}
</span>
{f.help && !f.set && <span className="block text-xs text-muted">{f.help}</span>}
{f.options ? (
<Segmented
label={f.label}
@@ -170,7 +171,7 @@ 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 }: { onDone: () => void }) {
export function ConnectSupabaseButton({ onDone, onFail }: { onDone: () => void; onFail?: () => void }) {
const [busy, setBusy] = useState(false);
const [msg, setMsg] = useState("");
return (
@@ -185,7 +186,10 @@ export function ConnectSupabaseButton({ onDone }: { onDone: () => void }) {
const body = await res.json().catch(() => ({}));
if (body.url) return void (window.location.href = body.url);
setBusy(false);
if (!res.ok) setMsg(body.error ?? "Couldn't start the Supabase sign-in.");
if (!res.ok) {
setMsg(body.error ?? "Couldn't start the Supabase sign-in.");
onFail?.();
}
onDone();
}}
>
+16 -5
View File
@@ -194,24 +194,35 @@ function Steps({ steps }: { steps?: Section["steps"] }) {
}
export function Body({ s, data, signedIn, reload }: { s: Section; data: SetupStatus; signedIn: boolean; reload: () => void }) {
const [fallback, setFallback] = useState(false);
const form = s.fields && <KeyForm fields={s.fields} canWrite={data.canWrite} writeNote={data.writeNote} onSaved={reload} />;
return (
<>
{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} />}
{s.action === "connect" && <ConnectSupabaseButton onDone={reload} onFail={() => setFallback(true)} />}
{s.action === "connect" && (s.steps || s.fields) ? (
<details className="text-sm">
<summary className="cursor-pointer text-muted hover:text-ink">Or paste a connection string instead</summary>
<details className="text-sm" open={fallback} onToggle={(e) => setFallback(e.currentTarget.open)}>
<summary className="cursor-pointer text-muted hover:text-ink">Button didn&apos;t work? Paste a connection string instead</summary>
<div className="pt-3 space-y-4">
<Steps steps={s.steps} />
{s.fields && <KeyForm fields={s.fields} canWrite={data.canWrite} writeNote={data.writeNote} onSaved={reload} />}
{form}
</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">
<summary className="cursor-pointer text-muted hover:text-ink">Change these keys</summary>
<div className="pt-3 space-y-4">
<Steps steps={s.steps} />
{form}
</div>
</details>
) : (
<>
<Steps steps={s.steps} />
{s.command && <CopyCommand command={s.command} />}
{s.fields && <KeyForm fields={s.fields} canWrite={data.canWrite} writeNote={data.writeNote} onSaved={reload} />}
{form}
</>
)}
{s.action === "migrate" && <MigrateButton onDone={reload} />}
+6
View File
@@ -48,3 +48,9 @@ assert.equal(validate({ NEXT_PUBLIC_SUPABASE_URL: `https://supabase.com/dashboar
assert.equal(validate({ NEXT_PUBLIC_SUPABASE_URL: REF }).clean.NEXT_PUBLIC_SUPABASE_URL, `https://${REF}.supabase.co`);
assert.equal(validate({ NEXT_PUBLIC_SUPABASE_URL: `https://${REF}.supabase.co/` }).clean.NEXT_PUBLIC_SUPABASE_URL, `https://${REF}.supabase.co`);
assert.equal(validate({ NEXT_PUBLIC_SUPABASE_URL: "http://127.0.0.1:54321" }).clean.NEXT_PUBLIC_SUPABASE_URL, "http://127.0.0.1:54321");
// The database password goes into the connection string, URL-encoded, and is never saved on its own.
const db = validate({ SUPABASE_DB_URL: "postgresql://postgres.abc:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:5432/postgres", SUPABASE_DB_PASSWORD: "p@ss w/rd" });
assert.equal(db.clean.SUPABASE_DB_URL, "postgresql://postgres.abc:p%40ss%20w%2Frd@aws-0-us-east-1.pooler.supabase.com:5432/postgres");
assert.equal("SUPABASE_DB_PASSWORD" in db.clean, false);
assert.ok(validate({ SUPABASE_DB_URL: "postgresql://postgres.abc:[YOUR-PASSWORD]@h.pooler.supabase.com:5432/postgres" }).errors.SUPABASE_DB_URL);
+7 -2
View File
@@ -29,8 +29,10 @@ export const ENV_KEYS: Record<string, Spec> = {
label: "Database connection string", secret: true,
check: (v) =>
!/^postgres(ql)?:\/\/[^\s]+@[^\s]+$/.test(v) ? "Starts with postgresql:// (copy the Session pooler URI)"
: /\[YOUR-PASSWORD\]/i.test(v) ? "Replace [YOUR-PASSWORD] with your database password" : null,
: /\[YOUR-PASSWORD\]/i.test(v) ? "Type your database password in the box below" : null,
},
// Never saved: validate() puts it into SUPABASE_DB_URL's [YOUR-PASSWORD], so nobody edits the string by hand.
SUPABASE_DB_PASSWORD: { label: "Database password", secret: true, check: () => null },
PLAID_CLIENT_ID: { label: "Client ID", secret: false, check: (v) => (/^[a-f0-9]{24}$/.test(v) ? null : "24 letters and numbers, from Plaid → Developers → Keys") },
PLAID_SECRET: { label: "Secret", secret: true, check: (v) => (/^[a-f0-9]{30}$/.test(v) ? null : "30 letters and numbers, from Plaid → Developers → Keys") },
PLAID_ENV: { label: "Mode", secret: false, check: (v) => (/^(sandbox|production)$/.test(v) ? null : "sandbox or production") },
@@ -86,7 +88,10 @@ export function supabaseUrl(v: string) {
return ref ? `https://${ref}.supabase.co` : v.replace(/\/+$/, "");
}
export function validate(updates: Record<string, unknown>): { clean: Record<string, string>; errors: Record<string, string> } {
export function validate(input: Record<string, unknown>): { clean: Record<string, string>; errors: Record<string, string> } {
const { SUPABASE_DB_PASSWORD: pw, ...updates } = input;
if (typeof pw === "string" && pw && typeof updates.SUPABASE_DB_URL === "string")
updates.SUPABASE_DB_URL = updates.SUPABASE_DB_URL.replace(/\[YOUR-PASSWORD\]/gi, encodeURIComponent(pw));
const clean: Record<string, string> = {};
const errors: Record<string, string> = {};
for (const [k, raw] of Object.entries(updates)) {
+14 -11
View File
@@ -12,7 +12,7 @@ import { akahuGet } from "@/lib/providers/akahu";
export type StepStatus = "done" | "todo" | "error" | "optional";
export type Part = string | { href: string; label: string };
export type Field = { key: string; label: string; secret: boolean; set: boolean; hint: string | null; placeholder?: string; options?: string[] };
export type Field = { key: string; label: string; secret: boolean; set: boolean; hint: string | null; placeholder?: string; options?: string[]; help?: string };
export type HowTo = { text: string; href?: string; command?: string };
export type AiRow = { id: string; label: string; ready: boolean; reason?: string; howTo?: HowTo[] };
export type Section = {
@@ -101,15 +101,14 @@ export async function setupStatus(signedIn: boolean): Promise<SetupStatus> {
status: sb?.ok ? "done" : sb ? "error" : "todo",
note: sb?.ok ? (ref ? `Project ${ref}` : sb.message) : sb?.message,
steps: [
["Make a free account and project at ", { href: "https://supabase.com/dashboard/new", label: "supabase.com" }, ". Any name works. Save the database password it gives you."],
["Open ", { href: dash("/settings/api-keys"), label: "Project Settings → API Keys" }, " and copy the publishable and secret keys."],
["For the Project URL, copy the address from your browser's address bar on that page. broke works out the rest."],
["Paste all three below and press Save."],
["Make a free account and a new project at ", { href: "https://supabase.com/dashboard/new", label: "supabase.com" }, ". Any name works. Write down the database password you choose: you need it in the next step if the button there doesn't work."],
["When the project is ready, open ", { href: dash("/settings/api-keys"), label: "Project Settings → API Keys" }, "."],
["Copy three things from that page into the boxes below, then press Save."],
],
fields: fields(env, ["NEXT_PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY", "SUPABASE_SERVICE_ROLE_KEY"], {
NEXT_PUBLIC_SUPABASE_URL: { placeholder: "https://supabase.com/dashboard/project/… or https://xxxx.supabase.co" },
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: { placeholder: "sb_publishable_…" },
SUPABASE_SERVICE_ROLE_KEY: { placeholder: "sb_secret_…" },
NEXT_PUBLIC_SUPABASE_URL: { placeholder: "https://supabase.com/dashboard/project/…", help: "The address in your browser's address bar on the API Keys page." },
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: { placeholder: "sb_publishable_…", help: "Under Publishable key. Starts with sb_publishable_." },
SUPABASE_SERVICE_ROLE_KEY: { placeholder: "sb_secret_…", help: "Under Secret keys: press the eye to show it, then copy. Starts with sb_secret_." },
}),
};
@@ -121,10 +120,14 @@ export async function setupStatus(signedIn: boolean): Promise<SetupStatus> {
note: "Press the button, sign in to Supabase and approve broke. Nothing to copy.",
action: "connect",
steps: [
["In Supabase, click ", { href: dash("?showConnect=true"), label: "Connect" }, " and copy the Session pooler URI."],
["Put your database password where it says [YOUR-PASSWORD]. Lost it? ", { href: dash("/database/settings"), label: "Reset it here" }, "."],
["In Supabase, press ", { href: dash("?showConnect=true"), label: "Connect" }, " at the top of your project."],
["Under Method, choose Session pooler. Copy the connection string."],
["Paste it below with your database password, then press Save. broke puts the password in for you and creates all its tables at once."],
],
fields: fields(env, ["SUPABASE_DB_URL"], { SUPABASE_DB_URL: { placeholder: "postgresql://postgres.xxxx:password@…pooler.supabase.com:5432/postgres" } }),
fields: fields(env, ["SUPABASE_DB_URL", "SUPABASE_DB_PASSWORD"], {
SUPABASE_DB_URL: { placeholder: "postgresql://postgres.xxxx:[YOUR-PASSWORD]@…pooler.supabase.com:5432/postgres" },
SUPABASE_DB_PASSWORD: { help: "The one you chose when you made the project. Forgot it? Reset it under Project Settings, Database." },
}),
};
if (!sb?.ok) database = { ...database, note: "Finish the account database first.", action: undefined };
else if (isSet(env.SUPABASE_DB_URL) || mcpConnected(ref)) {