firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.84k forks source link

Handling anonymous user upgrade merge conflicts: Wrong error code #1435

Closed NikiFoD closed 6 years ago

NikiFoD commented 6 years ago

Hi!

I am following the documentation, to see if I don't need @SUPERCILEX 's fork anymore. Documentation states that:

When linking is unsuccessful due to user collision, an error with code ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT will be returned to onActivityResult()

However, I am not getting this error code. I am getting ErrorCodes.UNKNOWN_ERROR instead. The IdpResponse I get is:

IdpResponse{mUser=null, mToken='null', mSecret='null', mIsNewUser='false', mException=com.firebase.ui.auth.FirebaseUiException: Fake exception created, original: com.firebase.ui.auth.FirebaseUiException: Unknown error, original cause: com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException: User account merge conflict, mPendingCredential=null}

Scenario to reproduce:

User has signed in with a google account on my app. Change device or simply clear the data of my app on the phone, to be signed out from the app. Log in anonymously. Connect account using: enableAnonymousUsersAutoUpgrade() Then on onActivityResult(...) I get the IdpResponse shown above.

Am I missing something?

samtstern commented 6 years ago

@NikiFoD I am not able to reproduce this with the sample app in this repo. Here's what I did:

1) Open the sample app AuthUI activity, sign in with Google 2) Clear data 3) Open the sample app Anonymous upgrade activity 4) Sign in anonymously 5) Sign in with Google

The merge worked as expected.

NikiFoD commented 6 years ago

@samtstern I went through the sample app and found the problem.

When the sample app tries to upgrade the account from Anonymous it calls:

public void startAuthUI() {
        List<AuthUI.IdpConfig> providers = ConfigurationUtils.getConfiguredProviders(this);
        Intent intent = AuthUI.getInstance().createSignInIntentBuilder()
            .setLogo(R.drawable.firebase_auth_120dp)
            .setAvailableProviders(providers)
            .setIsSmartLockEnabled(false)
            .enableAnonymousUsersAutoUpgrade()
            .build();
        startActivityForResult(intent, RC_SIGN_IN);
    }

Try removing the line below and you'll get the error I got.

.setIsSmartLockEnabled(false)

So, the anonymous upgrade doesn't work with smart lock.

Is this a bug or the intended behaviour? In @SUPERCILEX 's fork, it does work with smart lock and I don't see a reason why it would be better to exclude it, but if this is the case, please have it written in the documentation, cause it's not clear for other devs.

Thanks

samtstern commented 6 years ago

@NikiFoD nice catch! I was able to reproduce and I think I found the issue.

samtstern commented 6 years ago

@SUPERCILEX the anonymous upgrade error is detected properly but it somehow gets lost in IdpResponse serialization. Digging into it...

samtstern commented 6 years ago

@NikiFoD this will be fixed in 4.2.0

samtstern commented 6 years ago

This was fixed and released in version 4.2.0

JuhaniLehtimaeki commented 6 years ago

4.2.0 does not fix this issue to me the requestCode is still returned as 0 even after updating to 4.2.0

NikiFoD commented 6 years ago

For me, the problem I described is solved and working fine. Maybe there is another problem you are running into? (I never had a problem with requestCode)

zafersnger commented 6 years ago

I have the same issue with phone authentication. I receive "User account merge conflict" error when I enable enableAnonymousUsersAutoUpgrade()

com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException: User account merge conflict
        at com.firebase.ui.auth.viewmodel.SignInViewModelBase.handleMergeFailure(SignInViewModelBase.java:35)
        at com.firebase.ui.auth.data.remote.SignInKickstarter.onActivityResult(SignInKickstarter.java:189)
        at com.firebase.ui.auth.KickoffActivity.onActivityResult(KickoffActivity.java:81)
        at android.app.Activity.dispatchActivityResult(Activity.java:7256)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4468)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515)
        at android.app.ActivityThread.-wrap22(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)