Profile and account lifecycle Required
Let people delete their account themselves
Put account deletion in settings, behind fresh proof of identity, and finish it within one month, as data requests sets. Say first what happens to the person's data and organisations.
How to do it
Show what deletion removes and what stays, such as invoices kept for tax law. A last owner of an organisation transfers or deletes it first, as never leave an organisation without an owner says. Then end every session, stop subscriptions and mark the account for deletion. Allow 14 days in which signing in cancels it, so the deletion still ends inside the month. State the date in the confirmation email. Then run the delete function from the data requests rule.
Example
const GRACE_DAYS = 14;
export async function requestAccountDeletion(db, user) {
if (await db.memberships.isLastOwnerAnywhere(user.id)) throw new ConflictError('Transfer or delete your organisations first.');
const deleteOn = addDays(new Date(), GRACE_DAYS);
await db.tx(async tx => {
await tx.users.scheduleDeletion(user.id, deleteOn);
await tx.sessions.deleteAllFor(user.id);
});
await billing.cancelSubscriptions(user.id);
await mailer.sendDeletionScheduled(user, deleteOn);
}
GRACE_PERIOD = timedelta(days=14)
def request_account_deletion(db, user) -> None:
if db.memberships.is_last_owner_anywhere(user.id):
raise Conflict("Transfer or delete your organisations first.")
delete_on = date.today() + GRACE_PERIOD
with db.transaction():
db.users.schedule_deletion(user.id, delete_on)
db.sessions.delete_all_for(user.id)
billing.cancel_subscriptions(user.id)
mailer.send_deletion_scheduled(user, delete_on)
How to check
Delete a test account. Its sessions end at once and the email states the date. After the grace period, a search of every store finds no trace except records the law requires.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers accounts playbook: https://agentwranglers.se/playbook/accounts/profile-and-account-lifecycle/account-deletion.