Repository navigation
Commit 633cce6
fix(auth-ui): the forgot-password form sends one reset request at a time (#32788)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu2tNhjjZZAybyTGwcxZ2XAm)_
Part of #32645
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:「忘记密码」表单一次只发一个重置请求,连点只发一次;另加一条服务端突发测试,钉住同一地址并发重置请求只答 200 或 429、不出
5xx。
- 为什么改:生产上连点「发送重置链接」出现 500。客户端这半边是真的(表单从未在请求期间禁用按钮);服务端在框架自己的组合里实测复现不出
500,那半边留在卡上待云端读数。
- 风险与回滚:只动 `@object-ui/auth` 的一个表单与两个测试文件,单个 revert
即回滚;失败的请求会释放表单,不会把按钮锁死。
- 先看:`ui/packages/auth/src/ForgotPasswordForm.tsx` 的
`handleSubmit`;`packages/plugins/plugin-auth/src/reset-request-mail-after-response.test.ts`
末尾新 describe。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/auth/src/__tests__/forgot-password-success-message.test.tsx`,预期
12 passed,其中「two synchronous submits send one reset request」为绿。
- 需要你做的:无,席位落地。
## What changes
- **`@object-ui/auth` — `ForgotPasswordForm`:** the email form's submit
handler ignores a submit while its reset request is pending (a ref read
and set synchronously in the handler, so a second submit fired before
React re-renders is dropped), and the button and email field are
disabled with the submitting label until the request answers. A request
that fails, a 429 included, releases the form so the next submit is
sent. The phone (SMS code) branch is unchanged.
- **`@objectstack/plugin-auth` — test only:** the card's acceptance pin,
as a new top-level describe in the reset harness file
(`reset-request-mail-after-response.test.ts`): eight concurrent `POST
/request-password-reset` for one address through
`AuthManager.handleRequest`, counted by the storage `AuthPlugin` wires
(`createLazyCacheRateLimitStorage` over `MemoryCacheAdapter`), under the
reset endpoint's rule as the auth settings bind writes it
(`customRules['/request-password-reset']`, 3 per 60 s).
- Changeset: `@object-ui/auth` patch. `@objectstack/plugin-auth` ships
no changed bytes (its `files` is `dist`, and only a test file changed),
so it carries none.
## Why — what was measured
**Client (the defect this PR fixes).** The form's only guard was the
provider's `isLoading`. `AuthProvider`'s `forgotPassword` never raises
it (that flag tracks the session read), so the button was never disabled
during a reset request and every click sent its own `POST
/request-password-reset`. That is the three XHRs in the card's DevTools
capture.
Before / after, the pin `two synchronous submits send one reset
request`:
- before (guard removed by ablation): `AssertionError: expected
"vi.fn()" to be called 1 times, but got 2 times`;
- after: one `forgotPassword` call, the button reads `Sending…` and is
disabled, the success screen follows.
**Server (not reproduced in the framework's own composition).** The
card's expected 500 did not occur in any run below. Every run answered
each request 200 (the uniform body) or 429 (`{"message":"Too many
requests. Please try again later."}`), and the server logged no error.
| Run (tree `objectstack@296e2ec`, this branch's base, after a full
build) | Burst | Answers |
|:---|:---|:---|
| `AuthManager.handleRequest`, cache-backed storage over
`MemoryCacheAdapter`, rule 3/60 s, address with an account | 8 | 3×200,
5×429 |
| same, address with no account | 8 | 3×200, 5×429 |
| real CRM backend, `os start`, `NODE_ENV=production` (the vendor's
limiter on by default), better-sqlite3 | 6, unknown and known address |
3×200, 3×429 |
| same backend on Postgres 16 | 6, 20 | 3×200, rest 429 |
| Postgres, with a live session cookie, then with a signed-out (revoked)
one | 3 each | 3×200 |
On Postgres every admitted request for the account minted its reset
token and recorded its identity mail (12 `sys_verification` reset rows
and 12 `sys_identity_email` rows for the 12 admitted requests).
The 500 the card shows has no top-level `message`, and in this code only
two paths answer that shape. One is an exception inside a vendor
endpoint, answered by the router with an empty-bodied 500. The other is
an exception out of `handleRequest` (for example from the rate limiter's
`consume`, which runs before any endpoint), answered by the host's
catch. Both write a server-side error line. Between the production cloud
pin (`c5758b0d`) and `main`, the rate limiter, its counter store, the
reset endpoint and the reset mail are unchanged. What did change is how
a forwarding host reaches the auth surface: PR #32707 routes
`auth.handleRequest` through the plugin's own route table. Every run
above is on `main`, after that change. The cause is therefore most
likely in the hosted composition, not in this code. The card stays open
for that reading.
The new burst pin is green on `main`. Its sensitivity was checked once:
a counter store that throws on the second write to one key turns both
cases red. The throw escapes `handleRequest` as a rejection, which a
host answers as exactly the message-less 500 above:
```
Error: ablation: the counter store refused a second write to one key
❯ incrementFixedWindowOnce src/rate-limit-storage.ts
Tests 2 failed | 12 skipped (14)
```
Restored afterwards with blob equal to `HEAD` (`8bcd840c61fc`) and an
empty `git diff HEAD`.
## Tests
- `pnpm --dir ui exec vitest run packages/auth/` — Test Files 45 passed
(45), Tests 461 passed (461).
- `pnpm --filter @object-ui/auth type-check` — exit 0.
- `pnpm --filter @objectstack/plugin-auth exec vitest run
src/reset-request-mail-after-response.test.ts` — Tests 14 passed (14).
- `pnpm --filter @objectstack/plugin-auth typecheck` — exit 0 (test
layer: `check:test-typecheck: OK`).
- `pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2` (the whole package, on `3c28e4b5`, before the merge of
`main`) — Test Files 265 passed (265), Tests 4943 passed, 10 skipped
(4953).
- After merging `main` (head `03979ba6`; the incoming commits touch none
of these packages): the reset harness file with
`rate-limit-concurrency.test.ts` and `rate-limit-storage.test.ts` — Test
Files 3 passed (3), Tests 43 passed (43); `packages/auth/` under `ui/` —
Tests 461 passed (461); both typechecks exit 0.
## Acceptance notes
- The card's first acceptance item (the plugin-auth burst test) is met
as a pin that holds on `main`; it does not show a defect in this code,
because none was found here.
- The card's second acceptance item (two synchronous submits, one
`forgotPassword` call) is met.
- The card's own reading says the client guard does not close the card,
so this PR is `Part of`, not a fix of the whole card. What stays open is
the production 500. The reading that would place it is the server log
line written at that moment, which is one of `Auth request error:`, `#
SERVER_ERROR:` or `better-auth returned error`, together with the
`cache` service the hosted runtime registers.
- Not changed: the reset rule, its budget, the uniform answer, or any
check on the door.
- The untranslated English fallback banner (`Auth request failed with
status 500`) the card mentions is left as it is. It is the client's
last-resort text for a body with no message.
- Branch: the harness assigned `claude/project-thread-6kjsre` (not
`claude/issue-32645-…`); the claim on the card names it.
## Verification
All readings below are on head `03979ba6`.
- `pnpm lint` — exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 66 commands for this diff; each was
run and recorded, and `--ran` reconciles: `66 derived, 66 run, 0
NOT-MEASURED, 0 UNRUN`.
- `pnpm --filter @objectstack/spec check:generated` (spec moved on
`main`): 13 of 14 artifacts current; `check:test-typecheck` first
stopped with `tsc … failed without diagnostics` at the default heap, and
re-run with `NODE_OPTIONS=--max-old-space-size=8192` it answers
`check:test-typecheck: OK`. Not an artifact of this diff, which does not
touch `packages/spec`.
<details><summary>Derived gate commands and exit codes (66)</summary>
```
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dev-prereqs.mjs --self-test :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
node scripts/check-sdui-manifest.mjs --self-test :: exit 0
node scripts/check-tenant-audit-census.mjs :: exit 0
node scripts/check-tenant-audit-census.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:skill-identifier-liveness :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgXjcwwHcA9BB8HRHe9)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgXjcwwHcA9BB8HRHe9
<!-- signed: domain:server#4 · os-sales ·
session_01L6bhgXjcwwHcA9BB8HRHe9 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c249611 commit 633cce6
4 files changed
Lines changed: 203 additions & 6 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
- ui/packages/auth/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
| 51 | + | |
43 | 52 | | |
44 | 53 | | |
| 54 | + | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
| |||
371 | 381 | | |
372 | 382 | | |
373 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
148 | 155 | | |
149 | 156 | | |
150 | 157 | | |
| |||
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
229 | 239 | | |
230 | 240 | | |
231 | 241 | | |
| |||
237 | 247 | | |
238 | 248 | | |
239 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
240 | 253 | | |
241 | 254 | | |
242 | 255 | | |
| |||
457 | 470 | | |
458 | 471 | | |
459 | 472 | | |
460 | | - | |
| 473 | + | |
461 | 474 | | |
462 | 475 | | |
463 | 476 | | |
464 | 477 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
468 | 481 | | |
469 | 482 | | |
470 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
0 commit comments