Mobile OTP Verification without signing in using Firebase Phone Auth

百般思念 提交于 2021-02-07 14:35:15

问题


I am currently making an android app where I need to verify if the user is entering correct mobile number using the OTP. The user is already signed in the application using his email and password. Now I need to verify the mobile number the user enters without using the signInWithCrendntial() method of firebase phone auth. How do i go about it ?

My mCallbacks is

                @Override
                public void onVerificationCompleted(PhoneAuthCredential credential) {
                    Toast.makeText(getApplicationContext(), "Verification Complete", Toast.LENGTH_SHORT).show();

                    showMessage("Success!!","OTP verified!" + credential);
                    cred = credential;
                    //btn_add_guest.setEnabled(true);

                }

                @Override
                public void onVerificationFailed(FirebaseException e) {
                    Toast.makeText(getApplicationContext(), "Verification Failed", Toast.LENGTH_SHORT).show();
                    Log.i(TAG,"Error is "+e.getMessage());
                }

                @Override
                public void onCodeSent(String verificationId,
                                       PhoneAuthProvider.ForceResendingToken token) {
                    Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_SHORT).show();
                    mVerificationId = verificationId;
                    mResendToken = token;

                    Log.i(TAG,"VERFICATION ID IS"+mVerificationId);
                    Log.i(TAG,"RESEND TOKEN"+mResendToken);
                    btn_add_guest.setEnabled(false);
                }
            };

I m calling this method on button Pressed where put_otp is textView where user enters the OTP.

verifyPhoneNumberWithCode(mVerificationId,put_otp.getText().toString());
                    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, put_otp.getText().toString());
                    Log.i(TAG,credential.getProvider());

private void verifyPhoneNumberWithCode(String verificationId, String code) {

        Log.i(TAG,"RESEND TOKEN IN METHOD IS"+mResendToken);    if(code.equals(mResendToken)&&verificationId.equals(mVerificationId)){
            Toast.makeText(AddGuestActivity.this, "Verification Success", Toast.LENGTH_SHORT).show();

            btn_add_guest.setEnabled(true);
        }
        else
            Toast.makeText(this,"Please provide correct OTP",Toast.LENGTH_SHORT).show();
    }

回答1:


You can link an email/pass account with a phone account https://firebase.google.com/docs/auth/android/account-linking?authuser=0



来源:https://stackoverflow.com/questions/55371291/mobile-otp-verification-without-signing-in-using-firebase-phone-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!