本文介绍了适用于Android的Firebase电话Auth,我们能否仅验证电话号码而无需创建用户帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,在这里我只想验证手机号码而不创建用户帐户.是否有可能?我正在使用以下代码

I am working on an android app, in where I just want to verify mobile number without creating a user account. Is it Possible? I am using the following code

   private void startPhoneNumberVerification(String phoneNumber) {

    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            this,               // Activity (for callback binding)
            mCallbacks);        // OnVerificationStateChangedCallbacks

}



private void verifyPhoneNumberWithCode(String verificationId, String code) {

    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);


     signInWithPhoneAuthCredential(credential); // this function is creating user account , if not present. But We Don't want this


}

如果用户帐户不存在,以下功能将创建用户帐户,但是我不想创建帐户,我只想验证用户输入的代码.有任何可用的回叫方法吗?

The following function will create user account if user account is not there, but I don't want to create account, I just want to verify the code entered by the user. Is there any call back method available for that?

private void signInWithPhoneAuthCredential(final PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {



                        dialog.dismiss();
                        FirebaseUser user = task.getResult().getUser();

                        Toast.makeText(LoginActivity.this, "Success " + user.getEmail(), Toast.LENGTH_SHORT).show();


                    } else {

                        Toast.makeText(LoginActivity.this, "Failed ", Toast.LENGTH_SHORT).show();

                        verifyPhoneNumberWithCode(mVerificationId, editText.getText().toString().trim());

                    }
                }
            });
}

推荐答案

验证电话号码会自动为该用户创建一个Firebase身份验证帐户.无法阻止创建此帐户,因为Firebase会使用它来确保它在下次启动应用程序时知道该用户.

Verifying a phone number automatically creates a Firebase Authentication account for that user. There is no way to prevent creating this account, as it is what Firebase uses to ensure it knows that user next time they start the app.

这篇关于适用于Android的Firebase电话Auth,我们能否仅验证电话号码而无需创建用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:13