Skip to content

Commit be99d0d

Browse files
authored
Set updated credential on iOS Auth errors (#1381)
* Set updated credential on iOS Auth errors * Add additional null checks
1 parent 4b97d0e commit be99d0d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

auth/src/ios/auth_ios.mm

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,15 @@ void AuthResultCallback(FIRAuthDataResult *_Nullable fir_auth_result, NSError *_
343343
}
344344
}
345345

346+
// If there is an error, and it has an updated credential, pass that along via the result.
347+
if (error != nullptr && error.userInfo != nullptr) {
348+
if (error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] != nullptr) {
349+
result.additional_user_info.updated_credential =
350+
ServiceUpdatedCredentialProvider::GetCredential(new FIRAuthCredentialPointer(
351+
error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey]));
352+
}
353+
}
354+
346355
ReferenceCountedFutureImpl &futures = auth_data->future_impl;
347356
futures.CompleteWithResult(handle, AuthErrorFromNSError(error),
348357
util::NSStringToString(error.localizedDescription).c_str(), result);
@@ -353,6 +362,16 @@ void AuthResultCallback(FIRUser *_Nullable user, NSError *_Nullable error,
353362
User *current_user = AssignUser(user, auth_data);
354363
AuthResult auth_result;
355364
if (current_user != nullptr) auth_result.user = *current_user;
365+
366+
// If there is an error, and it has an updated credential, pass that along via the result.
367+
if (error != nullptr && error.userInfo != nullptr) {
368+
if (error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] != nullptr) {
369+
auth_result.additional_user_info.updated_credential =
370+
ServiceUpdatedCredentialProvider::GetCredential(new FIRAuthCredentialPointer(
371+
error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey]));
372+
}
373+
}
374+
356375
ReferenceCountedFutureImpl &futures = auth_data->future_impl;
357376
futures.CompleteWithResult(handle, AuthErrorFromNSError(error),
358377
util::NSStringToString(error.localizedDescription).c_str(),
@@ -414,7 +433,7 @@ void SignInResultCallback(FIRAuthDataResult *_Nullable auth_result, NSError *_Nu
414433
util::NSDictionaryToStdMap(auth_result.additionalUserInfo.profile, &result.info.profile);
415434
}
416435

417-
if (error.userInfo != nullptr) {
436+
if (error != nullptr && error.userInfo != nullptr) {
418437
if (error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] != nullptr) {
419438
result.info.updated_credential = ServiceUpdatedCredentialProvider::GetCredential(
420439
new FIRAuthCredentialPointer(error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey]));

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ code.
631631
- Changes
632632
- Auth (Android): Fixed an issue where VerifyPhoneNumber's internal
633633
builder failed to create PhoneAuthOptions with certain compiler settings.
634+
- Auth (iOS): Fixed an issue where functions that return AuthResult
635+
were not including updated credentials when encountering errors.
634636
- Remote Config (Desktop): Additional fix for handling of non-English time
635637
zone names on Windows.
636638

0 commit comments

Comments
 (0)