fix: a rejected email code cannot be corrected — hold the code input instead of dropping to the factor chooser - #449
Open
dbeattie71 wants to merge 1 commit into
Conversation
`ClerkSignInPanel._onError` resets `_strategy` to `unknown` on every error. `showCodeInput` is `_strategy.requiresCode`, so that takes the code field off screen and returns the panel to the factor chooser. For a rejected code that is self-perpetuating. `signIn.needsFirstFactor` is still true, so the chooser is what the user lands on, and the only way forward is to pick the factor again — which re-prepares it, emailing a fresh code and invalidating the one already in their inbox. They then type the code they are looking at, which is now the previous one, and it is rejected in turn. Every retry races the inbox, so the loop has no exit. A rejected code is the one error recoverable where the user is standing: the verification it was checked against is still valid, so retyping is enough. Keep the strategy in that case and let the panel hold its position. The error still surfaces through `ClerkErrorListener`, and `onResend` is already on screen for anyone who does want a new code. Every other error resets as before. `form_code_incorrect` is matched through a new `ExternalErrorCollection.containsIncorrectCodeError`, following `containsExternalAccountNotFoundError`, and surfaced as `ClerkError.isIncorrectCode` so the panel reads the intent rather than a string. Note this is distinct from clerk-community#443, which reaches the same `form_code_incorrect` by re-preparing the factor on every submission. That one makes a *correct* code fail; this one makes an *incorrect* code unrecoverable. Fixing clerk-community#443 does not fix this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #448.
A mistyped email code cannot be corrected.
ClerkSignInPanel._onErrorresets_strategytounknownon every error, andshowCodeInputis_strategy.requiresCode— so a422 form_code_incorrecttakes the code field off screen and, sincesignIn.needsFirstFactoris still true, lands the user on the factor chooser. The only way forward from there re-prepares the factor, emailing a fresh code and invalidating the one already in their inbox. They type the code they are looking at, it is now the previous one, and it is rejected in turn. Every retry races the inbox.Changes
clerk_flutter— hold the panel's position for a rejected code.Clearing the strategy is right for errors that invalidate the chosen factor. It is wrong for
form_code_incorrect, where the verification is still valid and retyping is all that is needed._passwordand_codeare still cleared in both cases, so the field empties for a fresh attempt.Nothing else moves: the message still surfaces through
ClerkErrorListener, andonResendis already on screen for anyone who does want a new code.clerk_auth— name the condition rather than matching a string at the call site.on
ExternalErrorCollection, following the existingcontainsExternalAccountNotFoundError, surfaced onClerkErroras:Tests
Seven new tests in
clerk_auth, covering both predicates: the code present alone and among several errors, a different code (verification_expired), an empty collection, and aClerkErrorcarrying no external errors at all.dart analyzeandflutter analyzeclean; 679clerk_authtests and 735clerk_fluttertests pass on this branch.Relationship to #443
Same
form_code_incorrect, different defect. #443 makes a correct code fail by re-preparing on every submission; this makes an incorrect code unrecoverable. This branch is cut frommainand is independent of #443 — they can land in either order.Worth noting the two mask each other: with #443 present, every code fails, so nobody reaches the state where a correct retype would have succeeded. This was found only after applying #443's fix locally.