#16

Add account deletion in settings

MergedstylesshOwnermerged intofrom

Summary

  • add an Account settings danger zone with password-confirmed deletion and an accessible confirmation dialog
  • add authenticated real-account and demo-account deletion flows
  • remove linked Stalwart accounts, DKIM signatures, and domains before deleting the Redakt user, with retry-safe cleanup behavior
  • persist Stalwart account IDs and cover dependency teardown with regression tests

Validation

  • corepack pnpm test (36 tests passed)
  • corepack pnpm exec tsc --noEmit
  • focused ESLint on all changed TypeScript and JavaScript files
  • corepack pnpm build
  • desktop and 320px mobile browser verification of the confirmation flow
  • git diff --check

Activity

6
mikeyreviewed3mo ago
mikey3mo ago

Reviewed the account-deletion flow: the API route (app/api/settings/account/route.ts), the Stalwart dependency-teardown logic and its new tests (lib/data/accounts.ts, lib/stalwart/client.ts), the demo-mode path (lib/demo/store.ts), and the confirmation dialog (components/settings/account-settings.tsx).

What checks out:

  • The beforeDelete hook throws a plain Error on any Stalwart teardown failure; better-auth aborts deleteUser on any thrown error from beforeDelete, so a failed cleanup correctly prevents the user row (and its cascade-deleted domains/mailboxes/session/account rows) from being deleted — matches the PR's "retry-safe" claim.
  • destroyObjects treats notFound as an already-satisfied destroy and only fails on real notDestroyed reasons, so a retried deletion after a partial failure won't get wedged re-deleting already-gone objects.
  • Domain sweep validates the fetched Stalwart domain's id+name before including it, guarding against acting on a stale/mismatched ID.
  • Both deletion paths (real and demo) require a correct password before removing anything.
  • New lib/stalwart/client.test.mjs tests cover the happy path, the already-deleted/retry case, and the hard-failure case for destroyObjects.

One correctness/reliability finding — inline comment:

  • components/settings/account-settings.tsx:173 — the delete-confirmation form's await response.json() isn't guarded. A non-2xx response with a non-JSON body (proxy/WAF error page, 502, etc.) throws unhandled, leaving deleteBusy stuck true forever: no error message, disabled Cancel button, dialog frozen until page reload. Not a data-loss risk (the DB delete still requires the parsed password), but it's a real dead-end in the UI for an irreversible-action confirmation flow. Non-blocking but worth fixing before merge given the blast radius of this control.

No security issues found (password re-confirmation gates both real and demo deletion; CSRF is mitigated by the password requirement; DB cascade deletes and Stalwart-side cleanup are ordered correctly).

stylessh merged commit c7daa76 into main3mo ago

Branch stylessh/add-account-deletion has been merged.

Checking branch