fix(auth)!: return AuthResponse.none when GoTrue returns no session or user - #1088
Open
grdsdev wants to merge 2 commits into
Open
fix(auth)!: return AuthResponse.none when GoTrue returns no session or user#1088grdsdev wants to merge 2 commits into
grdsdev wants to merge 2 commits into
Conversation
…r user
verifyOTP(type: .emailChange) previously threw a DecodingError when
GoTrue's /verify endpoint returned the `{ msg, code }` body sent for the
first of the two confirmations required by a secure email change,
since AuthResponse could only decode a Session or a User.
AuthResponse gains a `.none` case for this shape, and `user` is now
`User?` instead of `User` so `(session: nil, user: nil)` is
representable.
BREAKING CHANGE: `AuthResponse.user` is now `User?` instead of `User`.
Update call sites that access `response.user` directly to handle the
optional (e.g. `response.user?.email`).
Linear: SDK-1022
…ne doc Addresses code review feedback on #1088 (SDK-1022): the import ordering in AuthClientTests.swift had regressed to a non-swift-format-canonical layout, and the `.none` doc didn't make clear it's a catch-all for any unrecognized response shape, not just the email-change confirmation case.
Coverage Report for CI Build 28853929393Coverage increased (+0.2%) to 83.199%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
spydon
approved these changes
Jul 7, 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.
Summary
verifyOTP(type: .emailChange)threw an uncaughtDecodingErrorwhen GoTrue's/verifyendpoint returned{ msg, code }— the body sent for the first of the two confirmations required by a secure email change.AuthResponsecould only decode aSessionor aUser, so any other shape crashed instead of returning a usable result. This brings the Swift SDK's auth response handling in line with the equivalent fix insupabase-js(supabase/supabase-js#2378, #2391).Changes
Sources/Auth/Types.swift:AuthResponsegains a.nonecase for when neitherSessionnorUserdecodes.public var useris nowUser?instead ofUserso(session: nil, user: nil)is representable.Tests/AuthTests/AuthResponseTests.swift/AuthClientTests.swift: added coverage for the{msg, code}email-change shape (new fixtureemail-change-single-confirmation.json) and forsignUp()when confirmation is required (already worked correctly — this was investigated and found to be a pre-existing behavior, now with regression coverage using the previously-orphanedsignup-response.jsonfixture).Tests/IntegrationTests/AuthClientIntegrationTests.swift: updated the few.useraccess sites to handle the new optional.Root cause
Sources/Auth/Types.swift:601-613(pre-fix) —AuthResponse.init(from:)tried decodingSession, thenUser, and threwDecodingError.dataCorruptedErrorif neither succeeded. GoTrue's intermediate email-change confirmation response matches neither shape, so every call crashed instead of returning a null result.Breaking change
AuthResponse.userchanges fromUser(non-optional) toUser?. Any code accessingresponse.user.somePropertydirectly needs to switch to optional chaining (response.user?.someProperty). This is necessary because the fix requires representing "neither session nor user was returned," which the previous non-optionalusercouldn't express.Test plan
Tests/AuthTests/AuthResponseTests.swift(testEmailChangeSingleConfirmation) — confirmed it failed with the exactDecodingErrorbefore the fixTests/AuthTests/AuthClientTests.swift(testVerifyOTPForEmailChangeSingleConfirmation)signUp()confirmation-required flow:testSignUpConfirmationRequired/testSignUpWhenConfirmationRequiredmake PLATFORM=IOS XCODEBUILD_ARGUMENT=test xcodebuild(all targets, 0 failures)Tests/IntegrationTestspackage builds cleanly (swift build --build-tests)Linear
Closes SDK-1022