From 5fa4f5aac467db35654c0e3cf6920738cb4b8753 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Tue, 5 Jun 2018 17:11:31 -0700 Subject: Promote users to non-anonymous status even when linking account w/o pw --- Firebase/Auth/CHANGELOG.md | 4 ++++ Firebase/Auth/Source/FIRUser.m | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'Firebase') diff --git a/Firebase/Auth/CHANGELOG.md b/Firebase/Auth/CHANGELOG.md index 292f8bd..2669fc0 100644 --- a/Firebase/Auth/CHANGELOG.md +++ b/Firebase/Auth/CHANGELOG.md @@ -1,3 +1,7 @@ +# v5.0.2 +- Fix an issue where anonymous accounts weren't correctly promoted to + non-anonymous when linked with passwordless email auth accounts. + # v5.0.1 - Restore 4.x level of support for extensions (#1357). diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index 04aa861..3f5bf35 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -541,7 +541,7 @@ static void callInMainThreadWithAuthDataResultAndError( - (void)updateEmail:(nullable NSString *)email password:(nullable NSString *)password callback:(nonnull FIRUserProfileChangeCallback)callback { - if (password && ![password length]){ + if (password && ![password length]) { callback([FIRAuthErrorUtils weakPasswordErrorWithServerResponseReason:kMissingPasswordReason]); return; } @@ -561,11 +561,9 @@ static void callInMainThreadWithAuthDataResultAndError( return; } if (email) { - self->_email = email; + self->_email = [email copy]; } - if (self->_email && password) { - self->_anonymous = NO; - self->_hasEmailPasswordCredential = YES; + if (self->_email) { if (!hadEmailPasswordCredential) { // The list of providers need to be updated for the newly added email-password provider. [self internalGetTokenWithCallback:^(NSString *_Nullable accessToken, @@ -586,6 +584,20 @@ static void callInMainThreadWithAuthDataResultAndError( callback(error); return; } + for (FIRGetAccountInfoResponseUser *userAccountInfo in response.users) { + // Set the account to non-anonymous if there are any providers, even if + // they're not email/password ones. + if (userAccountInfo.providerUserInfo.count > 0) { + self->_anonymous = NO; + } + for (FIRGetAccountInfoResponseProviderUserInfo *providerUserInfo in + userAccountInfo.providerUserInfo) { + if ([providerUserInfo.providerID isEqualToString:FIREmailAuthProviderID]) { + self->_hasEmailPasswordCredential = YES; + break; + } + } + } [self updateWithGetAccountInfoResponse:response]; if (![self updateKeychain:&error]) { callback(error); -- cgit v1.2.3