Repository navigation
Conversation
When a PKCE flow start request fails (for example a magic link request that is rate limited), its cleanup deleted the legacy code verifier key because that key mirrored the failed flow. The verifier of the earlier, still valid flow stayed in its slot, but callbacks without a flow id only read the legacy key, so the earlier link failed with "PKCE code verifier not found in storage". Point the legacy key back at the newest flow still in the slot index instead of deleting it.
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
🔍 Description
What changed?
removePKCEVerifier()inpackages/core/auth-js/src/lib/helpers.tsused to delete the legacy<storageKey>-code-verifierkey whenever it held the removed flow's verifier. Now it points that key at the newest flow still in the slot index, and deletes it only when no other flow is left. Nothing else changes. Slots are never cleared for other flows, and the no-flow-id path still touches only the legacy key.Tests:
test/helpers.test.ts: removing the newest of three flows leaves the legacy key holding the previous flow's verifier.test/GoTrueClient.pkce.test.ts: end-to-end with the existing synthetic fetch. The firstsignInWithOtpsucceeds and the second gets a 429.exchangeCodeForSession(code)must still send the first flow's verifier. The harness gains arateLimitedRequestsoption.Why was this change needed?
Every PKCE flow start (
signInWithOtp,resend,resetPasswordForEmail,signUp,updateUser,signInWithSSO) writes the legacy key and callsremovePKCEVerifier(flowId)when its request fails. So a failed start, such as a rate-limited second magic-link request, deleted the legacy key. The earlier link that is still valid then failed withAuthPKCECodeVerifierMissingError, because callbacks without a flow id only read the legacy key. The earlier verifier was still in its slot (#2569) and just wasn't reachable.Closes #2863
📸 Screenshots/Examples
🔄 Breaking changes
📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
Verification (Node v24.9.0, no Docker):
cd packages/core/auth-js && npx jest test/GoTrueClient.pkce.test.ts test/helpers.test.ts --coverage=falsenullinstead of"verifier-b".npx jest --coverage=false(all auth-js suites): 299 passed, 1 failed. On master it's 297 passed, 1 failed. The failure, plus the suites that don't run, need the Docker auth server (fetch failed) and are the same on both.pnpm nx build auth-js: passes.npx prettier --checkon the changed files: passes.npx commitlint --from HEAD~1: passes.pnpm nx lint auth-jsreports errors that already exist on master (no-undefinjest.config*.js, unused catch vars and a missingno-extra-semirule definition inhelpers.ts). None are on the changed lines.Behaviour notes for review:
appendPkceFlowIdToRedirectsmode, a successful exchange of the newest flow now leaves the legacy key on the previous pending flow instead of clearing it. That matches what the key is meant to do: mirror the most recent pending flow.