【发布时间】:2020-05-26 02:54:10
【问题描述】:
我已经在我的 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 flutter dart firebase-authentication one-time-password