Enable Banking: warn before the bank's permission runs out, and link again cleanly

- save when the permission ends (consent_until, migration 0032)
- Accounts warns two weeks ahead, says Needs attention once it ran out, and offers
  Link again; an expired or revoked session no longer shows a raw API error
- accounts and rows are keyed on identification_hash, which stays the same across
  links (the uid doesn't), so linking again adds no copies and keeps edits
- links made with the per-link uid move to the stable key on their next sync
- linking the same bank again replaces the old connection

Tested against the stand-in: first link, moving old IDs, linking again,
the warning and an expired permission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MangaValkandClaude Opus 5.5 committed 2026-11-19 17:23:49 +01:00
1 parent 0a97ddbcae
commit 514b2aac77
8 files changed
+88 -15

No files matched your search

+11 -1
View File
@@ -21,8 +21,12 @@ type Item = {
status?: string;
error?: string | null;
provider?: string;
consent_until?: string | null;
accounts: Account[];
};
// Bank feeds (Enable Banking...) need the bank's permission again after up to 180 days. Warn two weeks ahead.
const SOON_MS = 14 * 864e5;
const isFeedItem = (i: Item) => !!i.provider && i.provider !== "plaid" && i.provider !== "akahu";
const GROUPS: { type: string; label: string; icon: LucideIcon; debt: boolean }[] = [
{ type: "depository", label: "Cash", icon: Landmark, debt: false },
@@ -56,7 +60,7 @@ export default async function Accounts() {
const [{ data }, { data: manual }] = await Promise.all([
supabase
.from("plaid_items")
.select("id, institution_name, institution_logo, institution_color, last_synced_at, status, error, provider, accounts(id, name, official_name, custom_name, mask, type, subtype, current_balance, currency, home:home_balance, included, holdings(id, name, ticker, type, quantity, value, cost_basis))")
.select("id, institution_name, institution_logo, institution_color, last_synced_at, status, error, provider, consent_until, accounts(id, name, official_name, custom_name, mask, type, subtype, current_balance, currency, home:home_balance, included, holdings(id, name, ticker, type, quantity, value, cost_basis))")
.order("created_at"),
supabase.from("accounts").select("id, name, custom_name, mask, type, subtype, current_balance:balance, currency, home:home_balance, included").eq("manual", true).eq("user_id", user!.id),
]);
@@ -169,12 +173,18 @@ export default async function Accounts() {
{item.institution_name ?? "Bank"}
{item.status && item.status !== "ok" && <span className="text-xs font-medium text-bad border border-bad rounded-full px-2 py-0.5">Needs attention</span>}
</div>
{item.consent_until && (!item.status || item.status === "ok") && Date.parse(item.consent_until) - Date.now() < SOON_MS && (
<div className="text-xs text-bad">Your bank&apos;s permission runs out on {new Date(item.consent_until).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })}. Link it again before then to keep syncing.</div>
)}
<div className="text-xs text-muted">
{item.status && item.status !== "ok"
? item.status === "ITEM_LOGIN_REQUIRED" ? "Sign in to your bank again to keep syncing." : (item.error ?? "This connection stopped syncing.")
: `${holds(item.accounts) ? `${holds(item.accounts)} · ` : ""}${plural(item.accounts.length, "account")}${since.get(item.id) ? ` · history from ${new Date(`${since.get(item.id)}T12:00:00Z`).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", timeZone: "UTC" })}` : ""} · synced ${item.last_synced_at ? ago(item.last_synced_at) : "never"}`}
</div>
</div>
{isFeedItem(item) && ((item.status && item.status !== "ok") || (item.consent_until && Date.parse(item.consent_until) - Date.now() < SOON_MS)) && (
<Link href="/accounts/add" className="btn-primary">Link again</Link>
)}
<ConnectionActions itemId={item.id} broken={item.provider === "plaid" && !!item.status && item.status !== "ok"} name={item.institution_name ?? "this bank"} />
</div>
))}