Skip to content

Commit

Permalink
[Auth] Add default values for decoding nil properties in UserInfoImpl (
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 authored Nov 28, 2024
1 parent a2f04f4 commit 2e02253
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 7 additions & 1 deletion FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions FirebaseAuth/Sources/Swift/User/UserInfoImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e02253

Please sign in to comment.