Firebase - How to check whether a user has already signed up using Phone Number

后端 未结 7 1491
梦毁少年i
梦毁少年i 2021-01-04 02:57

I am using firebase phone Authentication . When a user creates a account using phone number and next time he creates account with same phone number Than I want to show a m

相关标签:
7条回答
  • 2021-01-04 03:38

    This is very easy way to check whether a user is already register with firebase.

     AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> 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();
                            if(task.getResult().getAdditionalUserInfo().isNewUser()){
                                register(user);
                            }else{
                                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                                startActivity(intent);
                            }
                            Toast.makeText(LoginActivity.this, "welcome"+user.getDisplayName(), Toast.LENGTH_SHORT).show();
                        } else {
                            // If sign in fails, display a message to the user.
                            Log.w(TAG, "signInWithCredential:failure", task.getException());
                            Toast.makeText(LoginActivity.this, "signin Failed", Toast.LENGTH_SHORT).show();
                        }
    
                        // ...
                    }
                });
    
    0 讨论(0)
提交回复
热议问题