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

Fix a bug where unlinking emailpassword doesn’t remove provider data #2370

Merged
merged 1 commit into from
Feb 9, 2019
Merged
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
36 changes: 19 additions & 17 deletions Firebase/Auth/Source/FIRUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,8 @@ - (void)unlinkFromProvider:(NSString *)provider
FIRSetAccountInfoRequest *setAccountInfoRequest =
[[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:requestConfiguration];
setAccountInfoRequest.accessToken = accessToken;
BOOL isEmailPasswordProvider = [provider isEqualToString:FIREmailAuthProviderID];
if (isEmailPasswordProvider) {

if ([provider isEqualToString:FIREmailAuthProviderID]) {
if (!self->_hasEmailPasswordCredential) {
completeAndCallbackWithError([FIRAuthErrorUtils noSuchProviderError]);
return;
Expand All @@ -1181,6 +1181,7 @@ - (void)unlinkFromProvider:(NSString *)provider
}
setAccountInfoRequest.deleteProviders = @[ provider ];
}

[FIRAuthBackend setAccountInfo:setAccountInfoRequest
callback:^(FIRSetAccountInfoResponse *_Nullable response,
NSError *_Nullable error) {
Expand All @@ -1189,23 +1190,24 @@ - (void)unlinkFromProvider:(NSString *)provider
completeAndCallbackWithError(error);
return;
}
if (isEmailPasswordProvider) {

// We can't just use the provider info objects in FIRSetAcccountInfoResponse because they
// don't have localID and email fields. Remove the specific provider manually.
NSMutableDictionary *mutableProviderData = [self->_providerData mutableCopy];
[mutableProviderData removeObjectForKey:provider];
self->_providerData = [mutableProviderData copy];

if ([provider isEqualToString:FIREmailAuthProviderID]) {
self->_hasEmailPasswordCredential = NO;
} else {
// We can't just use the provider info objects in FIRSetAcccountInfoResponse because they
// don't have localID and email fields. Remove the specific provider manually.
NSMutableDictionary *mutableProviderData = [self->_providerData mutableCopy];
[mutableProviderData removeObjectForKey:provider];
self->_providerData = [mutableProviderData copy];

#if TARGET_OS_IOS
// After successfully unlinking a phone auth provider, remove the phone number from the
// cached user info.
if ([provider isEqualToString:FIRPhoneAuthProviderID]) {
self->_phoneNumber = nil;
}
#endif
}
#if TARGET_OS_IOS
// After successfully unlinking a phone auth provider, remove the phone number from the
// cached user info.
if ([provider isEqualToString:FIRPhoneAuthProviderID]) {
self->_phoneNumber = nil;
}
#endif

if (response.IDToken && response.refreshToken) {
FIRSecureTokenService *tokenService = [[FIRSecureTokenService alloc]
initWithRequestConfiguration:requestConfiguration
Expand Down