From 2e02253fd1ce99145bcbf1bb367ccf61bd0ca46b Mon Sep 17 00:00:00 2001 From: Nick Cooke <36927374+ncooke3@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:49:20 -0500 Subject: [PATCH] [Auth] Add default values for decoding nil properties in UserInfoImpl (#14185) --- FirebaseAuth/CHANGELOG.md | 8 +++++++- .../Sources/Swift/User/UserInfoImpl.swift | 17 ++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index c91a44333f6..fd141940888 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -5,7 +5,13 @@ `Auth.currentUser` API. This resolves some Firebase 11 issues where the current user is unexpectedly `nil` at startup. - [fixed] Restore Firebase 10 decoding behavior to prevent user provider data - from being decoded as `nil`. (#14011) + from always being decoded as `nil` . Note that this fix was only needed for + cases where Firebase 11 was reading data written by Firebase 10. (#14011) +- [fixed] Restore Firebase 10 decoding behavior to prevent user provider data + from being decoded as `nil` when a user has multiple linked providers. Note + that this fix was only needed for cases where Firebase 11 was reading data + written by Firebase 10. Note that this fix will not be in the 11.6.0 zip and + Carthage distributions, but will be included from 11.6.0 onwards. (#14011) # 11.5.0 - [fixed] Restore pre-Firebase 11 decoding behavior to prevent users getting diff --git a/FirebaseAuth/Sources/Swift/User/UserInfoImpl.swift b/FirebaseAuth/Sources/Swift/User/UserInfoImpl.swift index 23ef4c8de9a..8d3b96d0e43 100644 --- a/FirebaseAuth/Sources/Swift/User/UserInfoImpl.swift +++ b/FirebaseAuth/Sources/Swift/User/UserInfoImpl.swift @@ -88,17 +88,16 @@ class UserInfoImpl: NSObject, UserInfo { } required convenience init?(coder: NSCoder) { - guard let providerID = coder.decodeObject( + let providerID = coder.decodeObject( of: [NSString.self], forKey: UserInfoImpl.kProviderIDCodingKey - ) as? String, - let userID = coder.decodeObject( - of: [NSString.self], - forKey: UserInfoImpl.kUserIDCodingKey - ) as? String - else { - return nil - } + ) as? String ?? "" + // Not all providers have a corresponding user ID (e.g. phone auth), so + // fall back to an empty string. + let userID = coder.decodeObject( + of: [NSString.self], + forKey: UserInfoImpl.kUserIDCodingKey + ) as? String ?? "" let displayName = coder.decodeObject( of: [NSString.self], forKey: UserInfoImpl.kDisplayNameCodingKey