#16
Add account deletion in settings
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
6mikeyreviewed3mo ago
c7daa76 into main3mo 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:
beforeDeletehook throws a plainErroron any Stalwart teardown failure; better-auth abortsdeleteUseron any thrown error frombeforeDelete, so a failed cleanup correctly prevents theuserrow (and its cascade-deleteddomains/mailboxes/session/accountrows) from being deleted — matches the PR's "retry-safe" claim.destroyObjectstreatsnotFoundas an already-satisfied destroy and only fails on realnotDestroyedreasons, so a retried deletion after a partial failure won't get wedged re-deleting already-gone objects.id+namebefore including it, guarding against acting on a stale/mismatched ID.lib/stalwart/client.test.mjstests cover the happy path, the already-deleted/retry case, and the hard-failure case fordestroyObjects.One correctness/reliability finding — inline comment:
components/settings/account-settings.tsx:173— the delete-confirmation form'sawait response.json()isn't guarded. A non-2xx response with a non-JSON body (proxy/WAF error page, 502, etc.) throws unhandled, leavingdeleteBusystucktrueforever: 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).