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

Autoupgrade results in empty providerData #504

Closed
lswang1618 opened this issue Aug 14, 2018 · 15 comments
Closed

Autoupgrade results in empty providerData #504

lswang1618 opened this issue Aug 14, 2018 · 15 comments
Assignees
Labels

Comments

@lswang1618
Copy link

iOS version: 11.4
Firebase SDK version: FirebaseCore 5.5.0
FirebaseUI version: 5.2.0
CocoaPods Version: 1.5.3

Step 3: Describe the problem:

When FUIAuth.defaultAuthUI()?.shouldAutoUpgradeAnonymousUsers = true, calling Auth.auth().currentUser?.providerData[0] from func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) results in a nil value.

So the display name and photoURL are not reachable. If the anonymous users bit is set to false, then providerData is no longer empty and works as expected.

Steps to reproduce:

  1. set FUIAuth.defaultAuthUI()?.shouldAutoUpgradeAnonymousUsers = true
  2. call Auth.auth().currentUser?.providerData[0] from func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?)
  3. Sign in using a provider from the firebase UI picker
  4. Observe that providerData is an empty array.

Observed Results:

providerData is an empty array []

Expected Results:

providerData should have length 1 with the login information after signing in with a firebase UI login provider.

@lswang1618
Copy link
Author

Hi, any updates on this one?

@morganchen12
Copy link
Contributor

I won't have time to look at it this week, but will try to address this next week.

@lswang1618
Copy link
Author

Okay thanks!

@morganchen12
Copy link
Contributor

After combing through the code, I'm not entirely sure if this is a bug in FirebaseUI (don't worry though, we can still push fix for it upstream). Does refreshing the user correctly populate the providerData dictionary?

@lswang1618
Copy link
Author

Debugged a little more, so if the authUI.shouldAutoUpgradeAnonymousUsers = false, the user is signed in through the provider and providerData is set, but if authUI.shouldAutoUpgradeAnonymousUsers = true, then the user is still an anonymous user even after logging in through a provider.

@lswang1618
Copy link
Author

More detail - this only happens on trying to sign in to an account that already exists and was upgraded. On trying to upgrade an account for the first time to a provider account that's never been used, it hangs on login, but the account is upgraded and visible in the Firebase console. It's just stuck with the spinner and never actually enters into func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?).

Sorry if this is getting messy...let me know if I can provide any other info.

@lswang1618
Copy link
Author

authDataResult is nil in func authUI also

@morganchen12
Copy link
Contributor

Looking at the project, it looks like it's missing several files (fonts/images) and doesn't build off of a clone. I can replace these with placeholders for now.

@lswang1618
Copy link
Author

Ah, sorry, I've mostly been working locally so didn't sync every file. But let me know if I can help with anything.

@victor-sarda
Copy link

Hi, I'm having the same issues here.

When I enable shouldAutoUpgradeAnonymousUsers it does convert the anonymous user to a permanent user if it did not exist but won't call the func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) auth delegate method.

Also, when I try to sign in still with shouldAutoUpgradeAnonymousUsers enabled from an anonymous user to an existing user, it does call the delegate method and I'm catching the mergeConflict error. This is what I expect to happen but I also expect authDataResult to not be nil, otherwise how am I supposed to sign in the existing user?

Let me now if I can help with anything 👍

@morganchen12
Copy link
Contributor

#512 partially fixes this issue, the fix to the behavior @victor-sarda describes is in #519.

@lswang1618
Copy link
Author

Thanks for the update! Does #512 also populate authDataResult even if there's a mergeConflict error?

@morganchen12
Copy link
Contributor

morganchen12 commented Sep 5, 2018

No. The docs around this are exceedingly poor, but the merge conflict error basically means the two accounts can't be properly joined, since they both have their own separate account state that can't be resolved cleanly. So in the case of this error your account is still anonymous and the login has failed, and providerData being empty is intentional.

In the case where this error arises, you should take the auth credential out of the userInfo dictionary of the error and use it to sign in, discarding the state of the anonymous user in favor of the user that your app user is trying to login as.

@morganchen12
Copy link
Contributor

I'll submit a PR for the docs shortly.

@morganchen12
Copy link
Contributor

The fix has been released in 5.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants