Skip to content

fix(gotrue): don't throw in verifyOTP when secure email/phone change returns no session#1448

Merged
spydon merged 2 commits into
mainfrom
fix/verify-otp-secure-email-change
Jun 22, 2026
Merged

fix(gotrue): don't throw in verifyOTP when secure email/phone change returns no session#1448
spydon merged 2 commits into
mainfrom
fix/verify-otp-secure-email-change

Conversation

@spydon

@spydon spydon commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 200 with 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.

verifyOTP assumed every successful verification returns a session and threw AuthException('An error occurred on token verification.') whenever session == null, breaking the legitimate intermediate step.

What is the new behavior?

verifyOTP now only saves the session and notifies subscribers when a session is actually present, and returns the intermediate response otherwise. This matches the auth-js client, which does not throw on a null session.

Additional context

  • No API surface change: the signature and AuthResponse return 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.
  • The secondary report in the issue (a 500/AuthRetryableFetchException when supplying a wrong OTP) stems from a runtime panic in the Go auth server's /verify handler, not the Flutter client, so it is out of scope here.
  • Updated the existing response with null session test to verify the intermediate response is returned instead of throwing.

…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
@spydon spydon requested a review from a team as a code owner June 22, 2026 10:02
@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Jun 22, 2026
@spydon spydon merged commit 44300ac into main Jun 22, 2026
27 checks passed
@spydon spydon deleted the fix/verify-otp-secure-email-change branch June 22, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth This issue or pull request is related to authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected AuthException during supabase auth verifyOTP email change flow

2 participants