documentation: Knowledge note for the accounts module (sign-up, sign-in, passwords, roles)
Back to our planType
documentation
Summary
Write the short note that explains how accounts work on the site: how a neighbor signs up and confirms the account, signs in (and stays signed in), changes or resets a password, and what each role can open. Agents read it before they change anything in the accounts module, instead of working it out from about 100 files.
Problem
The accounts module is the largest security surface of the site, and most of its rules live in hooks, request-context flags and server actions that only make sense together. An agent changing one of them today has to read the whole flow to know what it protects.
What the generated reference already shows, so the note doesn't repeat it: users, opens in a new tab lists access per operation, the six hook names and their files, the /verify/:id endpoint, the sign-in settings (2-hour token, 5 failed attempts, 10-minute lock, 1-hour reset link) and field access (role admin-only to write; the resend counters hidden). routes.md, opens in a new tab lists the six account pages and their metadata helpers. docs/architecture/data-model.md describes three of the hooks in a sentence each. The note adds the flows and why each guard exists, and links these pages.
Proposed fix
Write src/modules/accounts/README.md from the template. Owner's direction for every note (2026-11-06, Claude session, recorded on #712 and #719): a note explains the behavior and logic of its content types and code (what shows, where, when, who publishes or changes it, and the special rules), never a list of fields; and every link between fields is stated near the top, so no agent has to work it out from the code.
Links between fields the note states up front (each one checked in the code first):
- The account page's server action sets the request-context flag
CURRENT_PASSWORD_CONFIRMED(domain/passwordConfirmation.ts), andcms/requireCurrentPassword.tsrefuses a new password on your own account without it;NEW_EMAIL_CONFIRMED(domain/emailChange.ts) does the same forcms/requireConfirmedEmailChange.ts. No HTTP caller can set either flag. - The public sign-up sets
SIGN_UP_CONTEXT(domain/signUpContext.ts,data/signUp.ts) socms/firstAccountIsAdmin.tsdoesn't promote it: only Payload's first registration on an empty database makes an admin. verificationResendsandverificationResendsSinceon the account feedtakeResend(domain/verificationResends.ts): 3 resends per 3-hour window, stored on the account so it survives restarts.verificationSetsPasswordandverifiedTokenHashlink a resent link to the password step and the "already verified" answer (use-cases/verifyAccountFromLink.ts).rolemaps toCurrentUser.roleand to the header'sAccountSummary.staff(admin or editor), never the role itself (data/mappers.ts,domain/types.ts); a missing role counts as guest (platform/payload/roles.ts).- The emails' links are built from the configured site address and the module's paths, never the request's Host (
domain/linkToken.ts,domain/paths.ts,cms/users.ts). keepAccountEmails(cms/keepAccountEmails.ts) is handed bysrc/payload.config.tsto the verification module's retention task, so a confirmed address stays while an account uses it.
Behaviors and rules the note must cover (each with the file or test named):
- Sign-up makes a guest that can't sign in until its emailed link is confirmed on
/verify-accountwith the robot check (use-cases/signUpResident.ts,use-cases/verifyAccountFromLink.ts); Payload's own REST and GraphQL verify are refused (cms/verifyFromSiteOnly.ts) and the admin's verify page is sent to the site's bysrc/proxy.ts. - No answer says whether an account exists: sign-up, forgot password and sign-in answer the same way, and the slow work runs after the response (
after()inuse-cases/requestPasswordReset.ts,use-cases/signUpResident.ts; failures indata/failures.ts). - Public forms that send email pass a per-connection limit, the robot check, then a site-wide limit (
use-cases/guardPublicRequest.ts,domain/requestLimits.ts); counts are in memory (one PM2 process). - Forgot password works only from the site's page (
cms/forgotPasswordFromSiteOnly.ts, the admin page redirected bysrc/proxy.ts), and an unverified account gets no reset email (cms/noResetEmailWhileUnverified.ts). - "Keep me signed in" stretches the session, token and cookie to 7 days (
data/rememberedSession.ts,domain/sessionLifetimes.ts). - Agent accounts can't sign in with a password (
cms/noPasswordSignInForAgents.ts); an MCP key doesn't count as a signed-in account (data/session.ts). requireUsersends a visitor to sign in and gives a signed-in user without the role a 404 (use-cases/requireUser.ts); every account page stays out of search results (ACCOUNT_PAGE_PATHS).- Where messages come from (
ui/*Message*.ts,platform/lib/messages/accounts.ts) and that the server's own error text never reaches the page.
Tests to name under "Rules and the tests that protect them": actions*.test.ts, cms/*.test.ts (each guard), domain/verificationResends.test.ts, data/rememberedSession.payload.test.ts, use-cases/verifyAccountFromLink.test.ts, use-cases/requireUser.test.ts, and outside the module src/payload.config.emailChange.test.ts, src/payload.config.guestMigration.test.ts, src/proxy.test.ts.
Map entry: { "note": "src/modules/accounts/README.md", "paths": ["src/modules/accounts/**"] }
Acceptance criteria
- Not done:
src/modules/accounts/README.mdfollowsdocs/knowledge/note-template.mdand is at most 80 lines. - Not done: It explains behavior and logic, not fields: no field lists, props tables or route lists. It links the generated pages named above for those.
- Not done: Right after its opening sentences, a short list states every link between fields named above (relationships, values copied or derived, mapper inputs and the props they become, hooks that copy a value), each with its file.
- Not done: Every behavior listed above is covered or, if the code turns out different, the note says what the code does and this issue gets a comment saying what changed.
- Not done: Every statement names the file or test it comes from, checked against the code at the branch's base.
- Not done:
docs/knowledge/index.mdgets one short line for the note (a few words after the link). It stays within the budget check. - Not done:
docs/knowledge/map.jsongets the entry above. - Not done:
npm run agent-context -- --writehas been run and its generated rule committed, andnpm run agent-contextpasses. If the budget check fails, this issue is not done; trimming other always-loaded files is not part of this issue. - Not done: Known contradictions: none of #279, #158, #366 or #531 applies to this module. If a role guide in
docs/roles/states something about sign-in or roles that the code contradicts, comment it on #158 rather than editing the guide here. - Not done: No code changes. A bug or gap found in the code goes under the note's "Known gaps" and is filed as its own issue (labeled
scope-creep, linked here). - Not done:
Prettier,Knowledge sync,PR PolicyandAgent contextpass.
Files likely touched
src/modules/accounts/README.mddocs/knowledge/index.md(one line)docs/knowledge/map.json(one entry).claude/rules/generated/src--modules--accounts--README.md
Must not touch
- Code under
src/(the note itself excepted): this issue documents behavior and changes none. - Other notes, their generated rules, and the files the other note issues under #712 list.
docs/knowledge/note-template.mdand the session-start set (CLAUDE.md,AGENTS.md,docs/guidelines/guard-rails.md).docs/architecture/data-model.md,docs/ui/data-types.md,docs/ui/component-set-modules.md: read them and fold this area's facts into the note (decision 0019, section 7); report any drift in them in a comment on #712 instead of editing them, since every note issue reads them.src/modules/README.md,src/platform/README.md,docs/project.md(#725 owns them).docs/roles/**(#158 and the other note issues own the guides they check).
Open questions
- Session-start room. The index line needs room at session start, which #799 makes. This issue is blocked by #799 and is not Ready until it lands; the line then stays within the budget check.
- Dead code first. #728 (the audit, waiting for the owner's keep-or-drop marks) removes unused or unwanted code before a note describes it. This issue is marked blocked by #728; it can start once #728 has settled this area, even if other areas are still open there.
- Size: not set; a cloud session can't read the board. Suggested: M.
Area
tooling, auth
Priority
medium
Generated by Claude Code, opens in a new tab