我在flutter应用程序中实现了Firebase otp
*当我在设备上使用相同的号码时,它不会发送OTP
这是发送otp的代码
Future<void> verifyPhone() async {
final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verID) {
this.verificationId = verID;
};
final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) {
this.verificationId = verId;
};
final PhoneVerificationCompleted verifiedSuccess =
(AuthCredential phoneAuthCredential) {
print('verified');
};
final PhoneVerificationFailed verifyFailed = (AuthException exception) {
print('${exception.message}');
};
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: widget.phone,
timeout: const Duration(seconds: 5),
verificationCompleted: verifiedSuccess,
verificationFailed: verifyFailed,
codeSent: smsCodeSent,
codeAutoRetrievalTimeout: autoRetrieve);
log("OTP sent");
}
这是验证OTP的代码
signIn() async{
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId,
smsCode: enteredOtp,
);
await FirebaseAuth.instance.signInWithCredential(credential).then((user) {
//SOME CODE HERE
}).catchError((e) {
showAlert(
context: context,
title: "Empty or Invalid OTP",
);
log("Invalid OTP");
});
}
这是怎么了如何解决此问题并获得设备中相同编号的otp。
最佳答案
实际上,我认为这实际上是预期的和预期的用法。 (或接近它)就像Firebase可以通过推送通知确认电话身份一样,它甚至不发送文本,因为它已经过验证。 (通常仅在验证一次电话后才会发生)。但是,如果将其发送到设备所连接的电话号码以外的其他电话号码,则它将无法使用系统中的以前的VerificationID。
因此,我建议检查一下代码的哪些部分,而不是。检查代码和授权是否失败,或者它将继续到程序的下一部分完全授权。只是为了确保在其中添加一些打印语句。但是我很确定这应该是它的工作方式。
关于firebase - Firebase未将OTP发送到设备中的电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60156322/