diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index fd799061726..66a0b4101eb 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -1,4 +1,5 @@ # 11.1.0 +- [fixed] Fixed `Swift.error` conformance for `AuthErrorCode`. (#13430) - [added] Added custom provider support to `AuthProviderID`. Note that this change will be breaking to any code that implemented an exhaustive `switch` on `AuthProviderID` in 11.0.0 - the `switch` will need expansion. (#13429) diff --git a/FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift b/FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift index 58e7354b1ca..7f73876e89c 100644 --- a/FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift +++ b/FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift @@ -48,7 +48,7 @@ import Foundation } /// Error codes used by Firebase Auth. -@objc(FIRAuthErrorCode) public enum AuthErrorCode: Int { +@objc(FIRAuthErrorCode) public enum AuthErrorCode: Int, Error { /// Indicates a validation error with the custom token. case invalidCustomToken = 17000 @@ -537,6 +537,12 @@ import Foundation } } + /// The error code. It's redundant but implemented for compatibility with the Objective-C + /// implementation. + public var code: Self { + return self + } + var errorCodeString: String { switch self { case .invalidCustomToken: diff --git a/FirebaseAuth/Tests/Unit/SwiftAPI.swift b/FirebaseAuth/Tests/Unit/SwiftAPI.swift index cc25c6d2002..05193b27dfa 100644 --- a/FirebaseAuth/Tests/Unit/SwiftAPI.swift +++ b/FirebaseAuth/Tests/Unit/SwiftAPI.swift @@ -725,4 +725,22 @@ class AuthAPI_hOnlyTests: XCTestCase { return 9 } } + + func regression13430(error: NSError) -> Int { + if let firebaseError = error as? AuthErrorCode, firebaseError == .networkError { + return 1 + } + + if let firebaseError = error as? AuthErrorCode, firebaseError.code == .invalidPhoneNumber { + switch firebaseError.localizedDescription { + case "TOO_SHORT": + return 1 + case "TOO_LONG": + return 1 + default: + return 1 + } + } + return 2 + } }