Context
ADR-0021 shipped self-registration and explicitly rejected a password reset flow: "a reset is an email, and there is no email", so a forgotten password was to be an admin ticket. That admin route was never built, and the owner now wants the ordinary thing — "forgot password → send a reset link to the registered email." The blocker in ADR-0021 was cost: the project will not buy a mail provider. That is a transport problem, not a design one, and it can be solved for free in development.
Decision
- Revisit ADR-0021's "no reset" stance. Self-service reset is back, by emailed link. Everything else ADR-0021 decided stands.
- Two public endpoints in the auth module.
POST /auth/forgot-passwordtakes an email;POST /auth/reset-passwordtakes a token and a new password. Both are@Public(). - No user enumeration.
forgot-passwordalways answers200with the same empty-dataenvelope, whether or not the address has an account, and whether or not the email actually sent (a mail failure is logged, never surfaced). The web form shows one neutral message either way. It is throttled to five requests per hour per client (FORGOT_THROTTLE) — the abuse here is using the endpoint as a mailer, not guessing. - Tokens are hashed, single-use and short-lived. A request mints 32 random bytes; only the SHA-256 of that token is stored (
PasswordResetToken.tokenHash), the same way refresh tokens are stored — a database dump is not a set of live reset links. The raw token rides in the link${WEB_URL}/reset-password?token=…and nowhere else. It expires in 30 minutes (PASSWORD_RESET_TTL_MINUTES) andusedAtmakes it single-use. - The reset is claimed atomically.
reset-passwordflipsusedAtwith one conditionalupdateManythat matches only an unused, unexpired row, so two requests racing on the same link cannot both succeed — the same pattern refresh-token rotation uses. A missing, expired or already used token is one error,RESET_TOKEN_INVALID: distinguishing them would reveal whether a token ever existed. - Reset revokes every session. On success the password is rehashed at bcrypt cost 12 (one number for every password this system writes, ADR-0021), every _other_ outstanding reset token for the account is spent, and
revokeAllSessionsdrops every refresh token — as a password _change_ already does. Whoever knew the old password is signed out everywhere. The reset does not sign the user in; they sign in fresh with the new password. - Google-only accounts get nothing. An account with no local
passwordHashhas no password to reset, so no token is minted — indistinguishable from the no-account path. - A dev-first mail transport.
MailServiceininfra/mailpicks its transport at boot: a real server whenSMTP_URLis set; an in-memory JSON transport underNODE_ENV=test(hermetic, no network); otherwise a throwaway Ethereal test account, whose preview URL is logged so a developer can read the mail in a browser with no paid provider. The reset link is also logged directly, so the flow is completable from the logs alone.SMTP_URL(secret),MAIL_FROMandWEB_URLare new, optional/defaulted env vars. - New table
PasswordResetToken, added to the design (schema.target.prisma) first, then the live schema, with RLS enabled in its migration (ADR-0009). It carriesuserId, a uniquetokenHash,expiresAt,usedAtandcreatedAt, indexed onuserIdandexpiresAt. It is not part of the M1–M6 group; it lands with the auth work. RESET_TOKEN_INVALIDjoinsERROR_CODES, and two audit actions —user.password_reset_requestedanduser.password_reset— joinAUDIT_ACTIONS.
Alternatives considered
- Keep ADR-0021's admin-ticket stance. Rejected: the admin route was never built, and a self-service reset is the ordinary expectation. The only real objection was mail cost, and the Ethereal/JSON transport removes it for development.
- Store the raw token, or a JWT with no server row. Rejected: a stored raw token turns a database dump into live reset links, and a stateless JWT cannot be made single-use or revoked before it expires.
- A pending "verify then reset" state, or telling the user the email is unknown. Rejected: both leak which addresses have accounts, the same enumeration ADR-0021 was careful to avoid on the sign-up form.
- Signing the user in on a successful reset. Rejected: the reset revokes every session by design; minting a new one in the same breath undoes half of that and hides the "you were signed out everywhere" behaviour the user should see.
Consequences
- A forgotten password is no longer an admin ticket; the admin module owes one less route.
- The project can develop and demo the whole flow with no paid provider. Production needs
SMTP_URLpointed at a real server; nothing else changes. - One more table and one more secret (
SMTP_URL) to carry. The table follows every rule the others do (timestamptz, RLS, hashed secret), so it adds no new pattern. - A reset, like a password change, signs the user out everywhere including the tab they reset from. The web client already handles that for password change; the reset page states it plainly.
- ADR-0021 is not superseded — it still governs registration, the password policy and refresh-token reuse detection. Only its "no password reset flow" bullet is reversed, and this ADR records why.