// What the Account page's "Delete my account" section says and decides // (docs/website/ACCOUNT_DELETION.md §4.1, §4.2). Plain JS with tests, so the // words and the confirm rule can be checked without a browser. // // The server is the guard: it checks the username, the password and the code // again whatever this file decides. What is here only keeps a mis-tap from // reaching it and turns its refusal codes into sentences. /** What goes with the account. The same list as BACKEND_DESIGN.md's. */ export const WHAT_GOES = [ 'your sign-in, password, email address, two-factor settings and recovery codes', 'every signed-in device, trusted device and push registration', 'your linked sign-ins, such as Google, Discord or Steam', 'your game-account links, and anything this site granted in the game through them', 'your notification settings and inbox', ] /** What stays, and who sees what of it. */ export const WHAT_STAYS = [ 'What you wrote where others read it, such as forum posts, stays. Other members see it as written by “[deleted player]”.', 'Reports you filed and appeals you made stay as moderation records. Staff can still see who it was, and the activity log keeps its IP addresses.', 'Event results stay with the score and the in-game name, with no site account behind them.', 'A game account stays on the game server. Only its link to this site goes.', ] /** Said only to staff: their name is never free again (AD9). */ export const STAFF_NAME_NOTE = 'You are staff, so your username can never be used again, by anyone, once this account is deleted.' /** True for every role but player. */ export const isStaffRole = (role) => Boolean(role) && role !== 'player' /** The confirm button is live once the typed name matches, ignoring case. */ export function usernameMatches(typed, username) { return typeof typed === 'string' && typeof username === 'string' && typed.trim().length > 0 && typed.trim().toLowerCase() === username.toLowerCase() } /** * True when the signed-in account is one of the demo's shared logins, which the * server refuses to delete. The section still shows (Play's reviewer must find * it); only its button is off. */ export function isSharedDemoLogin(settings, username) { const logins = settings?.demo?.logins if (!Array.isArray(logins) || typeof username !== 'string') return false const name = username.toLowerCase() return logins.some((l) => typeof l?.username === 'string' && l.username.toLowerCase() === name) } const BY_CODE = { username_mismatch: 'Type your username exactly as it is shown.', wrong_password: 'Your password is incorrect.', code_required: 'Enter a code from your authenticator app, or a recovery code.', wrong_code: 'That code is not valid. Try again.', password_required: 'This account has no password yet. Set one in the Password section above, then delete the account.', last_admin: 'You are the only admin. Make someone else an admin before you delete your account.', DEMO_LOCKED: 'This is turned off on the demo site.', } /** A refusal from DELETE /auth/me/account, as one sentence. */ export function refusalMessage(err) { const code = err?.body?.code if (code && BY_CODE[code]) return BY_CODE[code] if (err?.status === 429) return 'Too many attempts. Wait a few minutes and try again.' return err?.message || 'Could not delete your account. Try again.' }