How to handle FirebaseAuthUserCollisionException

后端 未结 2 1658
自闭症患者
自闭症患者 2020-12-30 10:30

I started getting a FirebaseAuthUserCollisionException exception when I try to sign in with Facebook in my Android application

2条回答
  •  渐次进展
    2020-12-30 11:05

    There is no need for this, you can just allow multiple accounts merge under firebaase->authentication-> sign in method -> Advanced - > change (multiple accounts per email address.

    Firebase will merge the same email address but will give you different user UID.

    See sample below.

    AuthCredential authCredential =  FacebookAuthProvider.getCredential(token.getToken());
        
        mAuth.signInWithCredential(authCredential)
                .addOnCompleteListener(this, task -> {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        LoginFacebookGoogleActivity.this.updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
    
                        if(task.getException() instanceof FirebaseAuthUserCollisionException){
                            FirebaseAuthUserCollisionException exception = (FirebaseAuthUserCollisionException) task.getException();
    
                            //log this bundle into the analytics to analyze which details you want to collect
                            
                        }
    
                        Toast.makeText(LoginFacebookGoogleActivity.this, "Authentication failed " + task.getException(), Toast.LENGTH_SHORT).show();
                        LoginFacebookGoogleActivity.this.updateUI(null);
                    }
                });
    

提交回复
热议问题