更新时间:2023-12-05 21:28:04
在通过互联网和Firebase文档本身进行研究之后,我在使用Firebase身份验证的应用程序中找到了针对这两个步骤的身份验证的解决方案.
After research over internet and in firebase documentation itself I found solution to this two step authentication in app using firebase auth.
firebaseAuth.getCurrentUser().updatePhoneNumber(credential).addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "signInWithCredential:success");
Snackbar.make(findViewById(android.R.id.content), "Mobile Verified Successfully.",
Snackbar.LENGTH_SHORT).show();
} else {
Log.w(TAG, "signInWithCredential:failure", task.getException());
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
//mVerificationField.setError("Invalid code.");
Snackbar.make(findViewById(android.R.id.content), "Invalid Code.",
Snackbar.LENGTH_SHORT).show();
} else {
Toast.makeText(context,"signInWithCredential:failure"+task.getException(),
Snackbar.LENGTH_LONG).show();
}
}
}
});
只需将PhoneAuthCredential
传递给上述方法,它将验证电话是否已分配给您的现有帐户.确保没有任何其他帐户使用它.
Just pass the PhoneAuthCredential
to above method and it will verify the phone assigns to your existing account. Make sure it is not used by any other account.
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);