Skip to content

Commit d3e26c0

Browse files
paulb777google-labs-jules[bot]gemini-code-assist[bot]
authored
Fix invalid user token error (#14672)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent a95ddb1 commit d3e26c0

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
- [fixed] Fix a `fatalError` unenrolling from MFA. An invalid user token now throws an
3+
`invalidUserToken` error instead of crashing. (#14663)
4+
15
# 11.9.0
26
- [changed] Using reCAPTCHA Enterprise and Firebase Auth requires reCAPTCHA
37
Enterprise 18.7.0 or later.

FirebaseAuth/Sources/Swift/User/User.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ extension User: NSSecureCoding {}
10811081
anonymous: Bool) async throws -> User {
10821082
guard let accessToken = accessToken,
10831083
let refreshToken = refreshToken else {
1084-
fatalError("Internal FirebaseAuth Error: nil token")
1084+
throw AuthErrorUtils.invalidUserTokenError(message: "Invalid user token: accessToken or refreshToken is nil")
10851085
}
10861086
let tokenService = SecureTokenService(withRequestConfiguration: auth.requestConfiguration,
10871087
accessToken: accessToken,

FirebaseAuth/Tests/Unit/UserTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,23 @@ class UserTests: RPCBaseTests {
15541554
}
15551555
#endif
15561556

1557+
func testRetrieveUserWithInvalidToken() async throws {
1558+
let auth = try XCTUnwrap(self.auth)
1559+
do {
1560+
_ = try await User.retrieveUser(
1561+
withAuth: auth,
1562+
accessToken: nil,
1563+
accessTokenExpirationDate: Date(),
1564+
refreshToken: nil,
1565+
anonymous: false
1566+
)
1567+
XCTFail("Expected an error to be thrown")
1568+
} catch let error as NSError {
1569+
XCTAssertEqual(error.domain, AuthErrors.domain)
1570+
XCTAssertEqual(error.code, AuthErrorCode.invalidUserToken.rawValue)
1571+
}
1572+
}
1573+
15571574
// MARK: Private helper functions
15581575

15591576
private func expectVerifyPhoneNumberRequest(isLink: Bool = false) {

0 commit comments

Comments
 (0)