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,197 @@
|
||||
"use client";
|
||||
|
||||
import { Check, Copy, Eye, EyeOff } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import type { Field } from "@/lib/setup";
|
||||
|
||||
export function CopyCommand({ command }: { command: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
return (
|
||||
<div className="flex items-center gap-2 bg-[#111113] text-[#e6e6e6] rounded-xl pl-4 pr-1.5 py-1.5 font-mono text-[13px]">
|
||||
<code className="flex-1 overflow-x-auto whitespace-nowrap">{command}</code>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Copy command"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(command);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
} catch {
|
||||
/* clipboard blocked: the text is still selectable */
|
||||
}
|
||||
}}
|
||||
className="p-2 rounded-lg hover:bg-white/10 shrink-0"
|
||||
>
|
||||
{copied ? <Check size={15} /> : <Copy size={15} />}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const MODE_LABELS: Record<string, string> = { sandbox: "Test banks", production: "Real banks" };
|
||||
|
||||
// Two or three choices side by side. No choice picked = keep what's saved.
|
||||
export function Segmented({ label, value, options, onChange }: { label: string; value: string; options: { value: string; label: string }[]; onChange: (v: string) => void }) {
|
||||
return (
|
||||
<span role="radiogroup" aria-label={label} className="inline-flex gap-0.5 rounded-xl border border-line bg-canvas p-0.5">
|
||||
{options.map((o) => (
|
||||
<button
|
||||
key={o.value}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={value === o.value}
|
||||
onClick={() => onChange(o.value)}
|
||||
className={`px-3.5 py-1.5 rounded-[10px] text-sm transition-colors ${value === o.value ? "bg-surface text-ink font-medium shadow-[var(--shadow-card)]" : "text-muted hover:text-ink"}`}
|
||||
>
|
||||
{o.label}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
type Result = { ok: boolean; message: string } | null;
|
||||
|
||||
// Keys typed here go to POST /api/setup/env (localhost only). An empty input keeps the saved value.
|
||||
export function KeyForm({ fields, canWrite, writeNote, onSaved }: { fields: Field[]; canWrite: boolean; writeNote?: string; onSaved: () => void }) {
|
||||
const [values, setValues] = useState<Record<string, string>>({});
|
||||
const [show, setShow] = useState<Record<string, boolean>>({});
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [result, setResult] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const dirty = Object.values(values).some((v) => v.trim());
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const send = Object.fromEntries(Object.entries(values).filter(([, v]) => v.trim()));
|
||||
if (!Object.keys(send).length) return;
|
||||
setBusy(true);
|
||||
setResult(null);
|
||||
setErrors({});
|
||||
try {
|
||||
const res = await fetch("/api/setup/env", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ values: send }) });
|
||||
const body = (await res.json().catch(() => ({}))) as { errors?: Record<string, string>; error?: string; checks?: Record<string, Result>; restart?: boolean };
|
||||
if (body.errors) setErrors(body.errors);
|
||||
else if (!res.ok) setResult({ ok: false, text: body.error ?? "Couldn't save." });
|
||||
else {
|
||||
const checks = Object.values(body.checks ?? {}).filter((c): c is { ok: boolean; message: string } => !!c);
|
||||
const bad = checks.find((c) => !c.ok);
|
||||
const text = bad ? `Saved, but: ${bad.message}` : checks.map((c) => c.message).join(" ") || "Saved.";
|
||||
setResult({ ok: !bad, text: body.restart ? `${text} Restart broke to use the new keys.` : text });
|
||||
setValues({});
|
||||
onSaved();
|
||||
}
|
||||
} catch {
|
||||
setResult({ ok: false, text: "Couldn't reach broke. Is it still running?" });
|
||||
}
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
if (!canWrite) return <p className="text-sm text-muted">{writeNote}</p>;
|
||||
|
||||
return (
|
||||
<form onSubmit={save} className="space-y-3">
|
||||
{fields.map((f) => (
|
||||
<label key={f.key} className="block space-y-1">
|
||||
<span className="flex items-center justify-between gap-2 text-sm">
|
||||
<span className="font-medium">{f.label}</span>
|
||||
{f.set && (
|
||||
<span className="text-xs text-good inline-flex items-center gap-1">
|
||||
<Check size={12} /> Saved{f.hint && f.hint !== "saved" && <span className="font-mono text-muted">{f.hint}</span>}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{f.options ? (
|
||||
<Segmented
|
||||
label={f.label}
|
||||
value={values[f.key] ?? ""}
|
||||
onChange={(v) => setValues({ ...values, [f.key]: v })}
|
||||
options={f.options.map((o) => ({ value: o, label: MODE_LABELS[o] ?? o }))}
|
||||
/>
|
||||
) : (
|
||||
<span className="relative block">
|
||||
<input
|
||||
type={f.secret && !show[f.key] ? "password" : "text"}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
value={values[f.key] ?? ""}
|
||||
onChange={(e) => setValues({ ...values, [f.key]: e.target.value })}
|
||||
placeholder={f.set ? "Saved. Paste a new value to replace it" : f.placeholder}
|
||||
aria-invalid={!!errors[f.key]}
|
||||
className={`select font-mono !text-[13px] ${f.secret ? "pr-10" : ""} ${errors[f.key] ? "!border-bad" : ""}`}
|
||||
/>
|
||||
{f.secret && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={show[f.key] ? "Hide" : "Show"}
|
||||
onClick={() => setShow({ ...show, [f.key]: !show[f.key] })}
|
||||
className="absolute right-1.5 top-1/2 -translate-y-1/2 p-1.5 rounded-lg text-muted hover:text-ink hover:bg-[var(--hover)]"
|
||||
>
|
||||
{show[f.key] ? <EyeOff size={15} /> : <Eye size={15} />}
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{errors[f.key] && <span className="block text-xs text-bad">{errors[f.key]}</span>}
|
||||
</label>
|
||||
))}
|
||||
<div className="flex flex-wrap items-center gap-3 pt-1">
|
||||
<button className="btn-primary" disabled={busy || !dirty}>{busy ? "Saving and checking…" : "Save"}</button>
|
||||
{result && <span className={`text-sm ${result.ok ? "text-good" : "text-bad"}`}>{result.text}</span>}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export function MigrateButton({ onDone }: { onDone: () => void }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState("");
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
className="btn-primary"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
setMsg("");
|
||||
const res = await fetch("/api/setup/migrate", { method: "POST" });
|
||||
const body = await res.json().catch(() => ({}));
|
||||
setBusy(false);
|
||||
setMsg(res.ok ? "Database updated." : body.error ?? "The update didn't finish.");
|
||||
onDone();
|
||||
}}
|
||||
>
|
||||
{busy ? "Updating..." : "Update database"}
|
||||
</button>
|
||||
{msg && <span className="text-sm text-muted">{msg}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// One click: Supabase's own sign-in page, then back to /setup with the tables created.
|
||||
export function ConnectSupabaseButton({ onDone }: { onDone: () => void }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState("");
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
className="btn-primary"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
setMsg("");
|
||||
const res = await fetch("/api/setup/supabase/connect", { method: "POST" });
|
||||
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.");
|
||||
onDone();
|
||||
}}
|
||||
>
|
||||
{busy ? "Opening Supabase..." : "Connect Supabase"}
|
||||
</button>
|
||||
{msg && <span className="text-sm text-bad">{msg}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
"use client";
|
||||
|
||||
import { Check, ChevronDown, CircleAlert, ExternalLink, RefreshCw } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import type { AiRow, Part, Section, SetupStatus } from "@/lib/setup";
|
||||
import { CopyCommand, KeyForm, ConnectSupabaseButton, MigrateButton } from "./SetupActions";
|
||||
|
||||
export function ExtLink({ href, children }: { href: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<a href={href} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-0.5 font-medium text-brand underline decoration-brand/30 underline-offset-2 hover:decoration-brand">
|
||||
{children}
|
||||
<ExternalLink size={12} className="shrink-0" />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
// `code` inside plain text renders as an inline code chip.
|
||||
const ticks = (t: string) => t.split(/(`[^`]+`)/).map((p, i) => (p.startsWith("`") ? <code key={i} className="font-mono text-[0.92em] bg-canvas border border-line rounded px-1">{p.slice(1, -1)}</code> : p));
|
||||
const line = (parts: Part[]) => parts.map((p, i) => (typeof p === "string" ? p : <ExtLink key={i} href={p.href}>{p.label}</ExtLink>));
|
||||
|
||||
// Height animates via grid rows (0fr -> 1fr); globals.css turns transitions off for reduced motion.
|
||||
export function Collapse({ open, children }: { open: boolean; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className={`grid transition-[grid-template-rows,opacity] duration-300 ease-[cubic-bezier(.33,1,.68,1)] ${open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"}`}>
|
||||
<div className="overflow-hidden" inert={!open}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Badge({ s, n }: { s: Section["status"]; n: number }) {
|
||||
if (s === "done") return <span className="size-7 rounded-full bg-good text-on-ink grid place-items-center shrink-0"><Check size={15} strokeWidth={2.5} /></span>;
|
||||
if (s === "error") return <span className="size-7 rounded-full bg-red-50 text-bad grid place-items-center shrink-0"><CircleAlert size={16} /></span>;
|
||||
return <span className="size-7 rounded-full border border-line text-sm text-muted grid place-items-center shrink-0 tabular">{n}</span>;
|
||||
}
|
||||
|
||||
export function SetupChecklist({ signedIn }: { signedIn: boolean }) {
|
||||
const [data, setData] = useState<SetupStatus | null>(null);
|
||||
const [checking, setChecking] = useState(true);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
const [moreOpen, setMoreOpen] = useState(false);
|
||||
|
||||
const load = useCallback(async (keepOpen?: string) => {
|
||||
setChecking(true);
|
||||
try {
|
||||
const res = await fetch("/api/setup/status", { cache: "no-store" });
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
const next = (await res.json()) as SetupStatus;
|
||||
setData(next);
|
||||
setFailed(false);
|
||||
// Open the next thing to do; keep a section open while the user is part-way through it.
|
||||
const first = next.sections.find((s) => s.kind !== "more" && s.status !== "done");
|
||||
setOpen((cur) => {
|
||||
const still = (id?: string | null) => id && next.sections.find((s) => s.id === id)?.status !== "done";
|
||||
return still(keepOpen) ? keepOpen! : still(cur) ? cur : first?.id ?? null;
|
||||
});
|
||||
} catch {
|
||||
setFailed(true);
|
||||
}
|
||||
setChecking(false);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const sections = data?.sections ?? [];
|
||||
const main = sections.filter((s) => s.kind !== "more");
|
||||
const more = sections.filter((s) => s.kind === "more");
|
||||
const required = main.filter((s) => s.kind === "required");
|
||||
const done = required.filter((s) => s.status === "done").length;
|
||||
const next = required.find((s) => s.status !== "done");
|
||||
const canSkipBank = next?.id === "plaid"; // the database works, so broke can open: statements can be imported without a bank feed
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-canvas px-4 py-8 md:py-12">
|
||||
<div className="@container max-w-2xl mx-auto space-y-4">
|
||||
<div className="flex items-center justify-between pb-2">
|
||||
<Logo />
|
||||
{signedIn && <Link href="/" className="text-sm text-muted hover:text-ink">Back to broke</Link>}
|
||||
</div>
|
||||
|
||||
<section className="card p-7 space-y-5">
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-2xl font-semibold">{!data ? "Set up broke" : !next ? "You're all set" : `Step ${done + 1} of ${required.length}: ${next.title}`}</h1>
|
||||
<p className="text-sm text-muted">
|
||||
{!data ? "Checking what's connected… " : !next ? "Open broke and sign in with your email. " : "It's free. Follow the steps below and paste each key in. "}
|
||||
Your keys stay on this computer.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-1.5" aria-hidden>
|
||||
{(data ? required.map((s) => s.status === "done") : [false, false, false]).map((d, i) => (
|
||||
<span key={i} className={`h-1.5 flex-1 rounded-full transition-colors duration-300 ${d ? "bg-good" : "bg-line"}`} />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
{next ? (
|
||||
<button
|
||||
className="btn-primary"
|
||||
onClick={() => {
|
||||
setOpen(next.id);
|
||||
document.getElementById(`s-${next.id}`)?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}}
|
||||
>
|
||||
Show me this step
|
||||
</button>
|
||||
) : (
|
||||
data && <Link href="/" className="btn-primary">Open broke</Link>
|
||||
)}
|
||||
{canSkipBank && <Link href="/" className="btn">Skip banks for now</Link>}
|
||||
<button className="text-sm text-muted hover:text-ink inline-flex items-center gap-1.5" disabled={checking} onClick={() => load()}>
|
||||
<RefreshCw size={14} className={checking ? "animate-spin" : ""} /> {checking ? "Checking" : "Check again"}
|
||||
</button>
|
||||
{failed && <span className="text-sm text-bad">Couldn't check. Is broke still running?</span>}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{!data && !failed && <div className="space-y-3" aria-busy="true">{[0, 1, 2, 3].map((i) => <div key={i} className="card h-[72px] animate-pulse" />)}</div>}
|
||||
|
||||
{data && main.map((s, i) => (
|
||||
<SectionCard key={s.id} s={s} n={i + 1} open={open === s.id} onToggle={() => setOpen(open === s.id ? null : s.id)} data={data} signedIn={signedIn} reload={() => load(s.id)} />
|
||||
))}
|
||||
|
||||
{data && !!more.length && (
|
||||
<section className="card overflow-hidden">
|
||||
<button className="w-full flex items-center gap-4 px-6 py-4 text-left row-hover" aria-expanded={moreOpen} onClick={() => setMoreOpen(!moreOpen)}>
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className="block font-medium">More options</span>
|
||||
<span className="block text-sm text-muted truncate">Local AI model, Claude Code, skip sign-in while testing</span>
|
||||
</span>
|
||||
<ChevronDown size={18} className={`text-muted shrink-0 transition-transform duration-300 ${moreOpen ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
<Collapse open={moreOpen}>
|
||||
<div className="border-t border-line divide-y divide-line">
|
||||
{more.map((s) => (
|
||||
<div key={s.id} className="px-6 py-5 space-y-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex-1">
|
||||
<div className="font-medium">{s.title}</div>
|
||||
<p className="text-sm text-muted">{s.what}</p>
|
||||
</div>
|
||||
{s.status === "done" && <span className="text-xs font-medium text-good inline-flex items-center gap-1 pt-1"><Check size={13} /> On</span>}
|
||||
</div>
|
||||
<Body s={s} data={data} signedIn={signedIn} reload={() => load()} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Collapse>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<p className="text-xs text-muted text-center px-4 pt-2">
|
||||
Keys are saved to <code>.env.local</code> next to Start broke.command. This page only ever shows whether each one is saved.
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function SectionCard({ s, n, open, onToggle, data, signedIn, reload }: { s: Section; n: number; open: boolean; onToggle: () => void; data: SetupStatus; signedIn: boolean; reload: () => void }) {
|
||||
const summary = s.status === "done" || s.status === "error" ? s.note ?? s.what : s.what;
|
||||
return (
|
||||
<section id={`s-${s.id}`} className={`card overflow-hidden scroll-mt-6 transition-shadow duration-300 ${open ? "shadow-[0_10px_24px_-12px_#0000001f]" : ""}`}>
|
||||
<button className="w-full flex items-center gap-4 px-6 py-4 text-left row-hover" aria-expanded={open} onClick={onToggle}>
|
||||
<Badge s={s.status} n={n} />
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className="block font-medium">{s.title}</span>
|
||||
<span className={`block text-sm truncate ${s.status === "error" ? "text-bad" : "text-muted"}`}>{summary}</span>
|
||||
</span>
|
||||
<ChevronDown size={18} className={`text-muted shrink-0 transition-transform duration-300 ${open ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
<Collapse open={open}>
|
||||
<div className="px-6 pb-6 pt-1 @md:pl-[4.25rem] space-y-4">
|
||||
<Body s={s} data={data} signedIn={signedIn} reload={reload} />
|
||||
</div>
|
||||
</Collapse>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Steps({ steps }: { steps?: Section["steps"] }) {
|
||||
if (!steps) return null;
|
||||
return (
|
||||
<ol className="space-y-1.5 text-sm">
|
||||
{steps.map((p, i) => (
|
||||
<li key={i} className="flex gap-2.5">
|
||||
<span className="text-muted tabular">{i + 1}.</span>
|
||||
<span>{line(p)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
);
|
||||
}
|
||||
|
||||
export function Body({ s, data, signedIn, reload }: { s: Section; data: SetupStatus; signedIn: boolean; reload: () => void }) {
|
||||
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" && (s.steps || s.fields) ? (
|
||||
<details className="text-sm">
|
||||
<summary className="cursor-pointer text-muted hover:text-ink">Or 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} />}
|
||||
</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} />}
|
||||
</>
|
||||
)}
|
||||
{s.action === "migrate" && <MigrateButton onDone={reload} />}
|
||||
{s.providers && <Providers rows={s.providers} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Providers({ rows }: { rows: AiRow[] }) {
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
return (
|
||||
<ul className="-mx-3">
|
||||
{rows.map((p) => {
|
||||
const can = !p.ready && !!p.howTo?.length;
|
||||
return (
|
||||
<li key={p.id}>
|
||||
<div className="flex items-center gap-3 px-3 py-2.5 rounded-xl">
|
||||
<span className={`size-2.5 rounded-full shrink-0 ${p.ready ? "bg-good" : "border-2 border-muted/40"}`} />
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className="block text-sm font-medium">{p.label}</span>
|
||||
<span className="block text-xs text-muted truncate">{p.ready ? "Ready" : ticks(p.reason ?? "Not set up")}</span>
|
||||
</span>
|
||||
{can && (
|
||||
<button className="text-sm font-medium text-brand inline-flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-brand-soft" aria-expanded={open === p.id} onClick={() => setOpen(open === p.id ? null : p.id)}>
|
||||
Set up <ChevronDown size={14} className={`transition-transform duration-300 ${open === p.id ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{can && (
|
||||
<Collapse open={open === p.id}>
|
||||
<ol className="px-3 pb-3 pl-8 space-y-2.5 text-sm">
|
||||
{p.howTo!.map((h, i) => (
|
||||
<li key={i} className="space-y-1.5">
|
||||
<span>{ticks(h.text)}{h.href && <> <ExtLink href={h.href}>Open</ExtLink></>}</span>
|
||||
{h.command && <CopyCommand command={h.command} />}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</Collapse>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Connect Supabase" results, keyed by the code its callback sends back.
|
||||
export const DB_MESSAGES: Record<string, string> = {
|
||||
cancelled: "Supabase sign-in was cancelled.",
|
||||
elsewhere: "This sign-in didn't start on this computer. Press Connect Supabase again.",
|
||||
rejected: "Supabase didn't accept the sign-in. Press Connect Supabase again.",
|
||||
"update-failed": "Connected, but a database update failed. Press Update database below to see why.",
|
||||
updated: "Connected. Tables updated.",
|
||||
current: "Connected. Tables are up to date.",
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { isHosted } from "@/lib/llm/providers";
|
||||
import { setupAccess, setupStatus, supabaseReady } from "@/lib/setup";
|
||||
import { DB_MESSAGES } from "./messages";
|
||||
import { SetupChecklist } from "./SetupChecklist";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
||||
// The checklist loads from /api/setup/status in the browser. Keeping provider calls out of this
|
||||
// server component means none of their request details end up in the page payload.
|
||||
export default async function Setup({ searchParams }: { searchParams: Promise<{ db?: string }> }) {
|
||||
// An online copy missing its keys: nobody can sign in, and they can't be saved from a page.
|
||||
if (isHosted() && !supabaseReady()) return (
|
||||
<main className="min-h-screen grid place-items-center px-4 bg-canvas">
|
||||
<section className="card p-8 max-w-lg space-y-3">
|
||||
<h1 className="text-2xl font-semibold">Add your keys in Vercel</h1>
|
||||
<ol className="space-y-2 text-sm list-decimal pl-5">
|
||||
<li>Open this project in <a className="underline underline-offset-2" href="https://vercel.com/dashboard">Vercel</a>, then Settings, Environment Variables.</li>
|
||||
<li>Add <code>NEXT_PUBLIC_SUPABASE_URL</code>, <code>NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY</code>, <code>SUPABASE_SERVICE_ROLE_KEY</code> and <code>SUPABASE_DB_URL</code> from your Supabase project.</li>
|
||||
<li>Open Deployments and press Redeploy.</li>
|
||||
</ol>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
const access = await setupAccess();
|
||||
if (!access.allowed) redirect("/login");
|
||||
const { db } = await searchParams; // result of "Connect Supabase", from its callback
|
||||
// Set up and signed in: the checklist is done, settings live inside the app.
|
||||
if (access.signedIn && (await setupStatus(true)).ready) redirect(db ? `/settings?db=${encodeURIComponent(db)}` : "/settings");
|
||||
return (
|
||||
<>
|
||||
{db && Object.hasOwn(DB_MESSAGES, db) && <p role="status" className="max-w-3xl mx-auto mt-6 px-4 text-sm">{DB_MESSAGES[db]}</p>}
|
||||
<SetupChecklist signedIn={access.signedIn} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user