Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] Add default values for decoding nil properties in UserInfoImpl #14185

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
paulb777 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading