fix(gotrue): don't throw in verifyOTP when secure email/phone change returns no session#1448
Merged
Merged
Conversation
…returns no session A secure email or phone change verifies in two steps. The server accepts the first OTP without returning a session and only issues one once the second OTP is verified. verifyOTP previously threw an AuthException whenever the session was null, breaking the legitimate intermediate step. Only persist the session and notify subscribers when a session is present, and return the intermediate response otherwise, matching auth-js behaviour. Fixes #981
grdsdev
approved these changes
Jun 22, 2026
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.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Closes #981.
When secure email change is enabled, the email-change OTP flow is two-step: the server accepts the first OTP and returns a
200with no session ({msg: "Confirmation link accepted. Please proceed to confirm link sent to the other email"}), only issuing a session once the second OTP is verified.verifyOTPassumed every successful verification returns a session and threwAuthException('An error occurred on token verification.')wheneversession == null, breaking the legitimate intermediate step.What is the new behavior?
verifyOTPnow only saves the session and notifies subscribers when a session is actually present, and returns the intermediate response otherwise. This matches theauth-jsclient, which does not throw on a null session.Additional context
AuthResponsereturn type are unchanged. Genuine server errors are still surfaced earlier by the fetch layer (non-2xx responses), so this only affects the previously-broken intermediate success case. Not a breaking change.500/AuthRetryableFetchExceptionwhen supplying a wrong OTP) stems from a runtime panic in the Goauthserver's/verifyhandler, not the Flutter client, so it is out of scope here.response with null sessiontest to verify the intermediate response is returned instead of throwing.