Skip to content

Commit 520ea85

Browse files
author
Chuan Ren
authored
Fix a bug where unlinking emailpassword doesn’t remove provider data (#2370)
1 parent f2f413c commit 520ea85

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Firebase/Auth/Source/FIRUser.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,8 @@ - (void)unlinkFromProvider:(NSString *)provider
11671167
FIRSetAccountInfoRequest *setAccountInfoRequest =
11681168
[[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:requestConfiguration];
11691169
setAccountInfoRequest.accessToken = accessToken;
1170-
BOOL isEmailPasswordProvider = [provider isEqualToString:FIREmailAuthProviderID];
1171-
if (isEmailPasswordProvider) {
1170+
1171+
if ([provider isEqualToString:FIREmailAuthProviderID]) {
11721172
if (!self->_hasEmailPasswordCredential) {
11731173
completeAndCallbackWithError([FIRAuthErrorUtils noSuchProviderError]);
11741174
return;
@@ -1181,6 +1181,7 @@ - (void)unlinkFromProvider:(NSString *)provider
11811181
}
11821182
setAccountInfoRequest.deleteProviders = @[ provider ];
11831183
}
1184+
11841185
[FIRAuthBackend setAccountInfo:setAccountInfoRequest
11851186
callback:^(FIRSetAccountInfoResponse *_Nullable response,
11861187
NSError *_Nullable error) {
@@ -1189,23 +1190,24 @@ - (void)unlinkFromProvider:(NSString *)provider
11891190
completeAndCallbackWithError(error);
11901191
return;
11911192
}
1192-
if (isEmailPasswordProvider) {
1193+
1194+
// We can't just use the provider info objects in FIRSetAcccountInfoResponse because they
1195+
// don't have localID and email fields. Remove the specific provider manually.
1196+
NSMutableDictionary *mutableProviderData = [self->_providerData mutableCopy];
1197+
[mutableProviderData removeObjectForKey:provider];
1198+
self->_providerData = [mutableProviderData copy];
1199+
1200+
if ([provider isEqualToString:FIREmailAuthProviderID]) {
11931201
self->_hasEmailPasswordCredential = NO;
1194-
} else {
1195-
// We can't just use the provider info objects in FIRSetAcccountInfoResponse because they
1196-
// don't have localID and email fields. Remove the specific provider manually.
1197-
NSMutableDictionary *mutableProviderData = [self->_providerData mutableCopy];
1198-
[mutableProviderData removeObjectForKey:provider];
1199-
self->_providerData = [mutableProviderData copy];
1200-
1201-
#if TARGET_OS_IOS
1202-
// After successfully unlinking a phone auth provider, remove the phone number from the
1203-
// cached user info.
1204-
if ([provider isEqualToString:FIRPhoneAuthProviderID]) {
1205-
self->_phoneNumber = nil;
1206-
}
1207-
#endif
12081202
}
1203+
#if TARGET_OS_IOS
1204+
// After successfully unlinking a phone auth provider, remove the phone number from the
1205+
// cached user info.
1206+
if ([provider isEqualToString:FIRPhoneAuthProviderID]) {
1207+
self->_phoneNumber = nil;
1208+
}
1209+
#endif
1210+
12091211
if (response.IDToken && response.refreshToken) {
12101212
FIRSecureTokenService *tokenService = [[FIRSecureTokenService alloc]
12111213
initWithRequestConfiguration:requestConfiguration

0 commit comments

Comments
 (0)