Skip to content

fix(login): show rate-limit copy for a passkey 429 and keep the session (TASK-22431) - #4079

Merged
kushagrasarathe merged 6 commits into
devfrom
fix/22431-auth-rate-limit
Nov 16, 2026
Merged

kushagrasarathe merged 6 commits into
devfrom
fix/22431-auth-rate-limit

Conversation

@kushagrasarathe

@kushagrasarathe kushagrasarathe commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A passkey 429 from the API (rate limit, see the API PR) showed the wrong thing:

  • 429 on /passkeys/*/options → "Couldn’t reach Peanut’s servers. Check your connection…" (NETWORK).
  • 429 on /passkeys/login/verify → ZeroDev read the error body as a success, threw "Login not verified", and it classified as LOGIN_ERROR. That path clears auth state.

Sentry PEANUT-UI-T34.

Fix

  • passkey-auth-capture.ts: any /passkeys/* response with status 429 throws PasskeyRateLimitedError before ZeroDev reads the body.
  • webauthn.utils.ts: new code RATE_LIMITED, copy "Too many attempts. Wait a minute and try again.", i18n key setup.passkey.rateLimited.
  • useZeroDev login: RATE_LIMITED keeps the session and reports a Sentry warning tagged passkey_rate_limited.
  • useSignupPasskey: signup shows the same copy.
  • login-session.ts: a 429 on /users/me during session hydration stops retrying and throws the same error (retries only spend the shared IP budget).
  • Catalogs: setup.passkey.rateLimited in en, es-419, es-AR and pt-BR.

Tests

  • passkey-auth-capture.test.ts: 429 on each of the 4 passkey paths throws PasskeyRateLimitedError.
  • webauthn.utils.test.ts: classifies as RATE_LIMITED with its copy and key.
  • useZeroDev-login-failure.test.tsx: 429 on login options and verify keeps auth state (fails without the hook change).
  • useSignupPasskey.test.tsx: signup shows the rate-limit copy.
  • login-session.test.ts: a hydration 429 stops at once with the rate-limit error.
  • Full jest suite: 19,868 passed; 54 failed in 22 marketing/content suites because the src/content submodule is not checked out in this worktree. None of those suites touch changed files.

Not verified

  • Not checked in a browser or on a device.
  • Step-up (/auth/step-up/* via apiFetch) 429s are not mapped; that flow keeps its existing errors.
  • Local tsc reports 176 missing-asset module errors in a fresh worktree, none in changed files. CI runs the real typecheck.
  • es-419, es-AR and pt-BR strings are mine, not a native speaker's.

Decisions (Kush, TASK-22431)

  • The es-419, es-AR and pt-BR strings ship as written.
  • No UI change came from the other decisions. The API now also caps signup at 60/min per IP; a signup 429 shows the same "Too many attempts" copy, which this PR already handles.

Coupled PR (api-contract)

peanut-api-ts PR: https://github.com/peanutprotocol/peanut-api-ts/pull/2125. The UI branches on HTTP status 429 only, which the API returns today from the global limit and after the API PR from the login limit. No body shape is read. Either PR can ship first.

Screen Library copy exception: setup.passkey.rateLimited needs a 429 from the passkey API mid-ceremony, which the capture harness cannot fake; no setup.passkey error has a capture state. The baseline also picks up dev drift (2 new unshown keys, 6 now-shown keys).

🤖 Generated with Claude Code

…(TASK-22431)

A 429 from /passkeys/*/options showed 'couldn't reach servers', and a 429
from /login/verify fell through to LOGIN_ERROR, which clears auth state.
The fetch wrapper now throws PasskeyRateLimitedError on any passkey 429; it
classifies as RATE_LIMITED with 'too many attempts, wait a minute' copy in
all four app locales, and login keeps the session.
…SK-22431)

After a passkey verifies, login reads /users/me. A 429 there was retried and
then shown as 'couldn't reach servers'. It now stops at once (retries only
spend the shared IP budget) and shows the rate-limit copy.
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
peanut-wallet Ready Ready Preview Nov 16, 2026 5:33am UTC

Request Review

@notion-workspace

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 11089.4 → 11090.26 (+0.86)
Findings: 0 net (+19 new, -19 resolved)

🆕 New findings (19)

  • critical complexity — src/utils/webauthn.utils.ts — CC 103, MI 51.67, SLOC 348
  • critical complexity — src/features/setup/useSignupPasskey.ts — CC 85, MI 50.59, SLOC 453
  • high hotspot — src/hooks/useZeroDev.ts — 74 commits, +827/-553 lines since 6 months ago
  • high method-complexity — src/features/setup/useSignupPasskey.ts:151 — CC 41 SLOC 204
  • medium high-mdd — src/features/setup/useSignupPasskey.ts:73 — useSignupPasskey: MDD 111.7 (uses across many lines from declarations)
  • medium high-mdd — src/hooks/useZeroDev.ts:94 — useZeroDev: MDD 77.9 (uses across many lines from declarations)
  • medium high-mdd — src/features/setup/useSignupPasskey.ts:151 — register: MDD 58.5 (uses across many lines from declarations)
  • medium high-mdd — src/utils/passkey-auth-capture.ts:146 — installPasskeyVerifyCapture: MDD 52.4 (uses across many lines from declarations)
  • medium high-mdd — src/utils/passkey-auth-capture.ts:152 — : MDD 50.8 (uses across many lines from declarations)
  • medium high-mdd — src/utils/webauthn.utils.ts:313 — classifyPasskeyError: MDD 38.3 (uses across many lines from declarations)
  • medium high-mdd — src/hooks/useZeroDev.ts:359 — : MDD 34.4 (uses across many lines from declarations)
  • medium method-complexity — src/utils/webauthn.utils.ts:313 — classifyPasskeyError CC 24 SLOC 86
  • medium complexity — src/utils/login-session.ts — CC 22, MI 67.91, SLOC 61
  • low high-dlt — src/utils/passkey-auth-capture.ts:146 — installPasskeyVerifyCapture: DLT 27 (calls 27 distinct functions — high context load)
  • low high-dlt — src/utils/passkey-auth-capture.ts:152 — : DLT 26 (calls 26 distinct functions — high context load)
  • low high-dlt — src/hooks/useZeroDev.ts:359 — : DLT 24 (calls 24 distinct functions — high context load)
  • low high-mdd — src/utils/webauthn.utils.ts:414 — withWebAuthnRetry: MDD 19.7 (uses across many lines from declarations)
  • low high-mdd — src/utils/login-session.ts:7 — recoverLoginSession: MDD 15.9 (uses across many lines from declarations)
  • low high-mdd — src/hooks/useZeroDev.ts:267 — handleLogin: MDD 11.6 (uses across many lines from declarations)

✅ Resolved (19)

  • src/utils/webauthn.utils.ts — CC 97, MI 51.6, SLOC 334
  • src/features/setup/useSignupPasskey.ts — CC 84, MI 50.82, SLOC 445
  • src/hooks/useZeroDev.ts — 73 commits, +824/-553 lines since 6 months ago
  • src/features/setup/useSignupPasskey.ts:151 — CC 40 SLOC 196
  • src/features/setup/useSignupPasskey.ts:73 — useSignupPasskey: MDD 108.8 (uses across many lines from declarations)
  • src/hooks/useZeroDev.ts:94 — useZeroDev: MDD 77.3 (uses across many lines from declarations)
  • src/features/setup/useSignupPasskey.ts:151 — register: MDD 55.2 (uses across many lines from declarations)
  • src/utils/passkey-auth-capture.ts:134 — installPasskeyVerifyCapture: MDD 51.1 (uses across many lines from declarations)
  • src/utils/passkey-auth-capture.ts:140 — : MDD 49.5 (uses across many lines from declarations)
  • src/utils/webauthn.utils.ts:307 — classifyPasskeyError: MDD 34.5 (uses across many lines from declarations)
  • src/hooks/useZeroDev.ts:356 — : MDD 34.4 (uses across many lines from declarations)
  • src/utils/webauthn.utils.ts:307 — classifyPasskeyError CC 22 SLOC 80
  • src/utils/login-session.ts — CC 21, MI 68.4, SLOC 59
  • src/utils/passkey-auth-capture.ts:134 — installPasskeyVerifyCapture: DLT 27 (calls 27 distinct functions — high context load)
  • src/utils/passkey-auth-capture.ts:140 — : DLT 26 (calls 26 distinct functions — high context load)
  • src/hooks/useZeroDev.ts:356 — : DLT 24 (calls 24 distinct functions — high context load)
  • src/utils/webauthn.utils.ts:403 — withWebAuthnRetry: MDD 19.7 (uses across many lines from declarations)
  • src/utils/login-session.ts:6 — recoverLoginSession: MDD 15.1 (uses across many lines from declarations)
  • src/hooks/useZeroDev.ts:267 — handleLogin: MDD 10.9 (uses across many lines from declarations)

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • ✅ unit: 21762 ran, 0 failed, 0 skipped, 7.8m

📊 Coverage (unit)

metric %
statements 88.5%
branches 81.9%
functions 82.7%
lines 90.0%
⏱ 10 slowest test cases
time test
🐢 21.2s scripts/__tests__/screens-adapter.test.js › runs the existing synthetic screen adapter Node acceptance suite
🐢 10.9s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with pointer
🐢 10.6s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with Enter
🐢 10.4s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with Space
🐢 9.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › Network failure keeps loading while retries remain, then shows the generic error
🐢 6.1s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › preserves ordinary Argentina selection for residence AR
🐢 5.7s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › preserves ordinary Argentina selection for residence null
🐢 5.7s scripts/__tests__/signup-attribution-paths.test.ts › includes newly published articles and locale fallbacks without editing the manifest
4.9s scripts/__tests__/indexable-urls.test.ts › excludes missing locale files, drafts, redirects, and retired pages from crawl and submission lists
4.1s src/features/payments/flows/qr-pay/__tests__/usePixPayment.test.tsx › reads a paid payment once more when its reward is not issued yet, then stops (API-CONTRACT-M5 §3)
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

@kushagrasarathe
kushagrasarathe marked this pull request as ready for review November 13, 2026 15:24

@chip-peanut-bot chip-peanut-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chip review — no blocking findings — this is not an approval

No findings in the passkey rate-limit handling change.

Checked clean

  • 429s from all four passkey paths become a rate-limit error before ZeroDev decodes the response; no verify token is stashed on failure.
  • Login preserves existing auth state and displays localized rate-limit copy; signup displays the same copy.
  • Session hydration propagates a /users/me 429 immediately, and the user query already disables retries for 429.
  • Exact-head CI reported ci-success; one screenshot capture check was still in progress when checked.

Security review by moonshotai/kimi-k3: 0 finding(s), marked with the model name. It reads the diff only and answers only security, privacy and money, so treat its findings as advice.

Third opinion by claude-opus: 0 finding(s), marked with the model name. It answers only product truth, missing tests and the cross-repo contract, so treat its findings as advice.

Copy check by claude-haiku-5-5: 0 finding(s), titled "Copy now wrong". Every quoted passage was checked against the file.

Exact head: a32f4b523d88 · Context: repo, product, sibling_api, ci · Took 5m (queued 1m)

dev added a retry window for login/verify 429 and 5xx (PasskeyVerifyRetryableError)
and reserved-username handling. keep both: login/verify 429 keeps dev's retry
window and now shows the rate-limit copy; every other passkey 429 still maps
to PasskeyRateLimitedError.
the merge commit staged the worktree's older checkout and reverted dev's bump;
this PR must not change the gitlink.
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

English

Open screen library dashboard

After merge: a003946 → aa9dbf9. Reviewable capture in English; newly registered states are marked in the report.

Before was captured with the base branch's own synthetic API because this PR changes it; differences can include synthetic-data changes.

…it copy

Dev's notifications rework and QR network pills left 6 stale and 2 unshown keys
that only a full PR capture catches. setup.passkey.rateLimited needs a mid-ceremony
429 the harness cannot fake, like every other passkey error key.

@chip-peanut-bot chip-peanut-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chip review — no blocking findings — this is not an approval

One signup rate-limit message gives a retry time that can be too short.

Findings

  • MAJOR · src/i18n/app/messages/en.json:1167 · Signup rate-limit copy promises one minute for an hourly cap
    The API applies a separate 20-per-IP, one-hour limit to /passkeys/register/verify (src/routes/passkey/index.ts, registrationRateLimit). If an IP reaches that cap near the start of the hour, this PR maps its 429 to the same message as the one-minute login/options limits, telling the user to retry in a minute while registration remains blocked for much longer. The same timing claim appears in the other three locales. Use a duration-neutral message for this path or surface the server retry time.

Checked clean

  • Exact-head diff against the supplied dev base isolates the passkey change and Screen Library copy-baseline update.
  • Login/verify 429 retains its bounded retry window and classifies as RATE_LIMITED without clearing auth state; options and hydration 429s also preserve the session.
  • The copy-baseline exception is present in the PR description; its additional keys reconcile inherited dev capture drift.
  • Exact-head CI had no failed checks when checked; several checks, including unit and screen capture, were still in progress.

Security review by moonshotai/kimi-k3: 0 finding(s), marked with the model name. It reads the diff only and answers only security, privacy and money, so treat its findings as advice.

Third opinion: did not run — it reads only the first review of a pull request; the first reviewer checks later rounds. This review is one reviewer short.

Copy check by claude-haiku-5-5: 0 finding(s), titled "Copy now wrong". Every quoted passage was checked against the file.

Exact head: daada76d9be7 · Context: repo, sibling_api, ci · Took 2m

Comment thread src/i18n/app/messages/en.json Resolved
The API keeps dev's 20-per-hour cap on /passkeys/register/verify, so
"wait a minute" can be false for up to an hour.

This branch was successfully deployed

1 active deployment
Preview — 8aa12006 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant