[auth][ios] Reload the user after updating the profile to ensure that it has up to date information

This commit is contained in:
Chris Bianca 2017-10-26 15:10:00 +01:00
parent 0549f962e2
commit 7b6d6c8728
1 changed files with 16 additions and 19 deletions

View File

@ -249,14 +249,7 @@ RCT_EXPORT_METHOD(reload:
FIRUser *user = [FIRAuth authWithApp:firApp].currentUser;
if (user) {
[user reloadWithCompletion:^(NSError *_Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
FIRUser *userAfterReload = [FIRAuth authWithApp:firApp].currentUser;
[self promiseWithUser:resolve rejecter:reject user:userAfterReload];
}
}];
[self reloadAndReturnUser:user resolver:resolve rejecter: reject];
} else {
[self promiseNoUser:resolve rejecter:reject isError:YES];
}
@ -400,8 +393,7 @@ RCT_EXPORT_METHOD(updateProfile:
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
FIRUser *userAfterUpdate = [FIRAuth authWithApp:firApp].currentUser;
[self promiseWithUser:resolve rejecter:reject user:userAfterUpdate];
[self reloadAndReturnUser:user resolver:resolve rejecter: reject];
}
}];
} else {
@ -795,15 +787,7 @@ RCT_EXPORT_METHOD(unlink:
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
// This is here to protect against bugs in the iOS SDK which don't
// correctly refresh the user object when unlinking certain accounts
[user reloadWithCompletion:^(NSError * _Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
[self promiseWithUser:resolve rejecter:reject user:user];
}
}];
[self reloadAndReturnUser:user resolver:resolve rejecter: reject];
}
}];
} else {
@ -917,6 +901,19 @@ RCT_EXPORT_METHOD(fetchProvidersForEmail:
return credential;
}
// This is here to protect against bugs in the iOS SDK which don't
// correctly refresh the user object when performing certain operations
- (void)reloadAndReturnUser:(FIRUser *)user
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject {
[user reloadWithCompletion:^(NSError * _Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
[self promiseWithUser:resolve rejecter:reject user:user];
}
}];
}
/**
Resolve or reject a promise based on isError value