Deleting Your Account
How a user deletes their own account with an emailed code, what goes with it, what blocks it, how subscriptions end and how to clean up your own data.
Settings → Profile → Delete account removes a user's account for good: no soft delete, no grace period and no undo. It works in every account mode. Deleting needs a code emailed to the user and a recent sign-in, so a stolen session alone can't do it.
This page is part of the Account documentation.
The Flow
- Delete my account opens a dialog. It lists the organizations that go with the account, how subscriptions end, and anything that blocks the delete. With a blocker, Email me a code is disabled.
- Email me a code sends a 6-digit code to the account's address (Step-Up Codes): 1 a minute and 5 an hour; past that the dialog shows the wait.
- The user types the code. The
deleteAccountaction checks everything again, then verifies and consumes the code, ends subscriptions in Stripe, and finally deletes the account and its sole-member organizations in one database transaction. Stripe cancellation happens before that transaction and cannot roll back with it. - The browser is signed out and lands on the public
/goodbyepage. A confirmation email goes to the old address, and the same address can sign up again at once.
A wrong, expired or used-up code is one message under the field and deletes nothing. The server code is createAccountDeletion in @kit/organizations/server (packages/organizations/src/account-deletion.ts), bound in apps/web/config/account-deletion.server.ts and called through accountDeletionFor(c) (apps/web/lib/organizations.server.ts) from the page actions in apps/web/pages/(app)/settings/profile.server.ts.
Cleanup can finish after the user is signed out. A failed hook does not restore the account; replay must be safe to repeat.
What Goes With the Account
- The user row and everything that cascades from it: sessions, sign-in methods (password, OAuth links, passkeys, 2FA), memberships, step-up codes and the invitations the user sent.
- Organizations where the user is the only member, with their members and invitations. They go through the same policies, delete steps and after-delete hooks as an organization delete.
- Rows in any purge target with
owner: 'user'(the kit's usage counters and yours) and the user's stored files (the avatar), purged in the background after the delete. - Subscriptions end in Stripe; the
subscriptionrows and the Stripe customer stay as ended billing records, as after an organization delete.
Not removed: other members' data in organizations the user merely belongs to. Every invitation the user sent from those organizations, pending or not, goes with them (the invitation's inviter is a cascade).
What Blocks It
The dialog names every blocker, and the server checks them again on Email me a code and on Delete:
| Blocker | Why | What to do |
|---|---|---|
| Only owner of an organization with other members | Deleting would leave it ownerless | The dialog links to that organization's members page: make someone else an owner |
| The last platform admin | The kit never deletes the last admin | Make another user an admin first |
| A sign-in older than 10 minutes, or an impersonation session | The same rule as changing the email or password | Sign out and sign in again; an admin can never delete the account they impersonate |
| A policy of yours (or the kit's billing guard with Stripe off) | Account policies | Whatever the policy's message says |
The database enforces the owner rule too: if an organization loses its other owner while the delete runs, the owner guard refuses at commit (LAST_OWNER), nothing is deleted, and the user stays signed in. If the organizations changed between the dialog and the delete (a member joined or left) the delete answers ACCOUNT_DELETION_CHANGED and deletes nothing. Either way the code is already used: the user asks for a new one.
Owner checks use your configured creator role. The preview and the final transaction apply the same rule.
The final transaction also takes the same administration lock as role changes and bans, locks the deleting user's row, and rechecks current admin eligibility before deleting anything. If another admin was demoted, banned or deleted meanwhile, a LAST_ADMIN refusal preserves the account and its organizations. The code has already been consumed: make another user an eligible admin, then request a new code. Subscription cancellation still happens before this locked transaction.
Subscriptions
Before the transaction, the user's own subscription and those of each organization deleted with them end in Stripe, as onDelete in apps/web/config/billing.config.ts says (Deleting an Organization); the dialog says how. Billing off: nothing to end, and a live subscription blocks the delete ("contact support"). If Stripe fails, nothing is deleted and the user sees "try again in a few minutes" with a new code.
Ending subscriptions and deleting are not one transaction (Stripe can't join it). If the delete fails or is refused after a cancel, the account stays: on the default plan with onDelete: 'immediately', or on its paid plan until the period ends with period_end. Trying again finds nothing left to cancel. Never keep billing someone nobody can sign in as.
After the Delete
Two outbox jobs are enqueued in the same transaction, so they exist exactly when the account is gone:
account.deleted-email: sends the confirmation (accountDeleted) to the address. Its payload holds the address and locale, because the user row is gone; the outbox deletes finished jobs after 7 days (dead ones after 90).account.deleted-hooks: runs yourafterOrganizationDeletehooks for each deleted organization, then yourafterAccountDeletehooks. A hook that throws fails the job and it retries from the first hook. The email is a separate job, so a hook's retry never sends it again.
Recipes
Hooks, steps and policies live in apps/web/config/account-hooks.config.server.ts (yours to edit): Exit Hooks has the recipes: delete a user's files, cancel an external resource, refuse a deletion.
Checking Concurrent Admin Changes
apps/web/db/__tests__/account-deletion.concurrency.test.ts proves deletion and moderation share their administration lock using independent PostgreSQL sessions. Run that file alone with one worker and KIT_TEST_POSTGRES_URL pointing at a disposable local PostgreSQL 17+ instance. The test requires permission to create databases, creates and removes its own uniquely named database, and rejects non-local hosts and URL query overrides. Without that variable it skips; PGlite tests do not prove this locking behavior.
Common Pitfalls
- A user-owned table with an unbounded number of rows and no purge target or cascade: its rows outlive the account. Cascade only a few rows per user; otherwise declare a purge target with
owner: 'user'(Purge Targets). - A hook that isn't idempotent: it runs again on every retry of the job.
- Doing external work in an
afterAccountDeletehook that needs the user's rows: they are gone. Use anaccountDeleteStepsstep, which runs before the delete. - Expecting the delete to be undoable, or to remove the Stripe customer: both are outside it.
Next: Exit Hooks →