Files
website/client/src/lib/deletedAccount.js
wtclaude d1ae8f943f
All checks were successful
PR Checks / bot-tests (pull_request) Successful in 37s
PR Checks / client-build (pull_request) Successful in 49s
PR Checks / server-tests (pull_request) Successful in 6m14s
feat(account): self-service account deletion, MODULE_API 1.20.0
ACCOUNT_DELETION.md phase 2 (core): a member deletes their own account on
the website, and the admin route runs the same procedure.

- DELETE /api/v1/auth/me/account: typed username, password always (AD7),
  and a 2FA or recovery code when 2FA is on. A wrong password or code is
  400, not 401 (AD12), so the app's refresh-on-401 never replays it.
  409 password_required and last_admin; the demo's shared logins are
  locked.
- auth/accountDeletion.js: module hooks first, then one transaction that
  reserves a staff username (reserved_usernames, AD9) and deletes the row,
  then a Teams reconcile, the audit entry (no username) and a notice to
  the old address (new protected template auth.account-deleted).
- MODULE_API 1.20.0: api.onUserDeleting({ userId, deletedBy }), before the
  delete, 10 s limit, cannot veto (AD10, AD11).
- utils/displayAuthor.js: a deleted account's username snapshots read
  "[deleted player]" to members and the stored name, marked, to staff
  (AD5, AD6). Used by the forum, the Reports queue, the guest list and
  the Team digest. A deleted account drops off Forum guests (AD13).
- Reserved names refuse at every username write, answered as "taken".
- Web: Delete my account on the player and staff Account pages; staff
  views mark "(deleted account)".
- OpenAPI regenerated; route manifest and engagement manifest regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
2026-10-29 18:32:19 -05:00

26 lines
1.1 KiB
JavaScript

// How a deleted account's name is shown (ACCOUNT_DELETION.md AD5, AD6).
//
// The server decides WHAT name a viewer gets (server/src/utils/displayAuthor.js):
// a member is sent "[deleted player]", staff are sent the stored name and a
// `…Deleted` flag. All this file does is mark the staff case, so a moderator
// reading "Ravenna" knows that account no longer exists.
export const DELETED_PLAYER = '[deleted player]'
/** "Ravenna (deleted account)" for staff; the placeholder is left as it is. */
export function markDeleted(name, deleted) {
if (!name) return name
return deleted && name !== DELETED_PLAYER ? `${name} (deleted account)` : name
}
/**
* The same for an admin view that is handed raw ledger rows (`actor_user_id`,
* `actor_username`): an id that is NULL beside a snapshot that is not is a
* deleted account, and nothing else clears those ids. Only an explicit null
* counts — a row that does not carry the id column at all says nothing.
*/
export function rowName(userId, username, fallback = '—') {
if (!username) return fallback
return markDeleted(username, userId === null)
}