Firebase-Auth phone for Android, is it possible to simply confirm the phone number without creating a user account

I am working on an Android application where I just want to check my mobile phone 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 a user account if the user account is not there, but I do not want to create an account, I just want to check the code entered by the user. Is there any callback method for this?

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());

                    }
                }
            });
}
+4
source share
2 answers

Firebase . , , Firebase , , .

+1

, , Firebase .

, :

FirebaseAuth.getInstance().getCurrentUser().
        unlink(PhoneAuthProvider.PROVIDER_ID)
        .addOnCompleteListener(this, onCompleteListener);

, , . , Firebase .

:

Google Play. onVerificationCompleted (PhoneAuthCredential) PhoneAuthProvider.OnVerificationStateChangedCallbacks. , , .

+2

Source: https://habr.com/ru/post/1679043/


All Articles