Files
brokeless/src/app/api/setup/status/route.ts
T
minimus7andClaude Opus 5.5 b532bb8dd8 Setup step 3 asks where you live and shows that country's bank feed (#6)
Saved as BROKE_COUNTRY. US and Canada get Plaid, NZ Akahu, UK and Europe
Enable Banking, Australia Basiq, Brazil Belvo. Countries with no feed are
told to import a statement after sign-in. Onboarding uses the saved
country instead of asking again.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 11:15:28 -06:00

26 lines
1.6 KiB
TypeScript

import { NextResponse } from "next/server";
import { countryOf, wantsAkahu } from "@/lib/countries";
import { currentEnv, fromLocalhost, setupAccess, setupStatus } from "@/lib/setup";
import { createClient } from "@/utils/supabase/server";
// Server setup details are for the owner on this machine only: setup writes already need localhost (writeGate).
export async function GET() {
const access = await setupAccess();
if (!access.allowed) return NextResponse.json({ error: "Sign in first" }, { status: 401 });
if (!(await fromLocalhost())) return NextResponse.json({ error: "Managed by the server owner" }, { status: 403 });
const status = await setupStatus(access.signedIn);
// The NZ bank keys only matter to someone with NZ banks. Keys already saved stay visible, so they can be changed or removed.
// Before Supabase is set up there's nobody signed in, and no client to ask.
const user = access.signedIn ? (await (await createClient()).auth.getUser()).data.user : null;
// Before anyone signs in, where they live is what setup step 3 asked (BROKE_COUNTRY).
const profile = user?.user_metadata?.profile ?? { country: currentEnv().BROKE_COUNTRY };
const here = countryOf(profile?.country).providers as string[];
const nz = wantsAkahu(profile);
// Bank connections for other countries stay out of the way, unless keys are already saved.
return NextResponse.json({ ...status, sections: status.sections.filter((s) => {
if (s.kind === "required") return true;
if (s.id === "akahu") return nz || s.status === "done";
return !["plaid", "enablebanking", "basiq", "belvo"].includes(s.id) || here.includes(s.id) || s.status === "done";
}) });
}