[英]Is there any way to know if AUTO VERIFICATION failed in firebase phone authentication?
Firebase電話認證非常棒。 我了解它具有自動驗證過程,有時不需要發送otp。 但是,有什么方法可以知道自動驗證是否失敗,然后才提示用戶輸入OTP。
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
if(notAutoRetrieval) {
//firebase send otp to the given phone number
}else{
//firebase does send otp to the given phone number
}
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
// if firebase send otp this method is execute
notAutoRetrieval=true;
}
@Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
Toast.makeText(LogIn.this,e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
// The SMS quota for the project has been exceeded
}else{
Toast.makeText(LogIn.this,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
請參閱此代碼。 可能對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.