Clear my data on the Database page

Disconnects every bank at Plaid and deletes the signed-in user's money data. Sign-in, profile and AI connection stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-04 12:11:50 -06:00
1 parent 9c4bf6198e
commit f2d7f36017
5 files changed
+97 -17

No files matched your search

+16
View File
@@ -44,3 +44,19 @@ export function plaidError(e: unknown): { code: string; message: string } {
if (typeof code === "string" && code.startsWith("AKAHU_") && e instanceof Error) return { code, message: e.message };
return { code: "ERROR", message: e instanceof Error ? e.message : "Plaid request failed" };
}
/** Revokes a bank connection at Plaid. Akahu tokens belong to the server owner, and a test connection can't be revoked
* from live mode (Plaid's sandbox forgets it anyway), so those are only forgotten. Already gone at Plaid counts as done. */
export async function revokeItem(item: { access_token: string | null; provider: string | null }) {
const testInLive = item.access_token?.startsWith("access-sandbox-") && process.env.PLAID_ENV !== "sandbox";
if (item.provider !== "plaid" || testInLive || !item.access_token) return { ok: true as const };
try {
await plaid.itemRemove({ access_token: item.access_token });
return { ok: true as const };
} catch (e) {
const err = plaidError(e);
if (err.code === "ITEM_NOT_FOUND" || err.code === "INVALID_ACCESS_TOKEN") return { ok: true as const };
console.error("[broke] item remove:", err);
return { ok: false as const };
}
}