Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Phone Authentication SMS Code null android

I have added firebase phone auth to my android project. First everything goes fine. After sometime, the sms code in onVerificationCompleted() is null.Thanks!!

PhoneAuthProvider.getInstance().verifyPhoneNumber(mobileNumber, 60, TimeUnit.SECONDS, FirebasePhoneAuthActivity.this, new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
    @Override
    public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
        smsCode = phoneAuthCredential.getSmsCode();
        Log.i(TAG, "onVerificationCompleted: CODE " + smsCode);
        Log.i(TAG, "onVerificationCompleted: PROVIDER " + phoneAuthCredential.getProvider());
    }

    @Override
    public void onVerificationFailed(FirebaseException e) {
        e.printStackTrace();
    }

    @Override
    public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        Log.i(TAG, "onCodeSent: CODE " + s);

    }

    @Override
    public void onCodeAutoRetrievalTimeOut(String s) {
        super.onCodeAutoRetrievalTimeOut(s);
        Log.i(TAG, "onCodeAutoRetrievalTimeOut: " + s);
    }
});
like image 243
Nandha Kumar Avatar asked Jan 19 '18 04:01

Nandha Kumar


1 Answers

This is Instant Verification. In the official docs, it says:

Instant verification: in some cases the phone number can be instantly verified without needing to send or enter a verification code.

Also, if you look at the open-sourced FirebaseUI for Android, on this line of code it suggests that there is a possibility of verification being a success, while sms code being absent. Such a case would denote Instant Verification. So you can safely continue to use this credential to sign the user in.

like image 131
Abdul Wasae Avatar answered Nov 14 '22 23:11

Abdul Wasae