dart 在重新发送OTP时收到相同的OTP,因此无法理解使用firebase OTP时OTP何时过期或为什么在重新发送时也相同

gmxoilav  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(137)

这是第一次请求OTP时使用的函数。

await _auth.verifyPhoneNumber(
                        phoneNumber: "+$countryCode ${phoneController.text}.",
                        verificationCompleted: (PhoneAuthCredential credential) async {
                          otpValue = credential.smsCode.toString();
                          showLoading = false;
                        },
                        verificationFailed: (verificationFailed) {
                          setState(() {
                            showLoading = false;
                            switch (verificationFailed.code) {
                              case "invalid-phone-number":
                                phoneError = "Please Enter valid phone number";
                                print("invalid-phone-number");
                                break;

                              case "too-many-requests":
                                phoneError = "too many requests,\nPlease try again after some time";
                                print("too many attempts");
                                break;
                            }
                            Navigator.pop(context);
                          });
                          print(verificationFailed.code);
                        },
                        codeSent: (verificationID, resendingToken) async {
                          setState(() {
                            showLoading = false;
                            // _isButtonDisabled = true;
                            print("check here");
                            this.verificationID = verificationID;
                            _resendToken = resendingToken;
                            Navigator.pop(context);//loading close
                            nextButtonLoginEnable = true;
                            print("check here 1");
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) => OTPWidget(
                                  number: phoneController.text,
                                  verificationId: verificationID,
                                  countryCode: countryCode,
                                  resendToken: _resendToken,
                                  smsCode: otpValue,
                                ),
                              ),
                            );
                          });
                        },
                        codeAutoRetrievalTimeout: (verificationID) async {});}

第二个是我检查OTP的顶部页面

if (otpController.text == "") {
                        print("is it in if");
                        setState(() {
                          otpErrorText = "Please enter OTP";
                        });
                      }
                      else if (otpController.text.length < 4) {
                        print("is it in else if");
                        setState(() {
                          otpErrorText = "Please enter 6 digit OTP number";
                        });
                      } else {
                        setState(() {
                          otpErrorText = "";
                          loaderforNavigate();
                        });
                        AuthCredential phoneAuthCredential =
                        PhoneAuthProvider.credential(
                            verificationId: widget.verificationId ?? "",
                            smsCode: otpController.text);}

但如果用户没有收到,则提供重新发送的选项。

await _auth.verifyPhoneNumber(
                                    phoneNumber:
                                        "+${widget.countryCode}${widget.number}.",
                                    verificationCompleted:
                                        (phoneAuthCredential) async {
                                      showLoading = false;
                                    },
                                    verificationFailed: (verificationFailed) {
                                      setState(() {
                                        showLoading = false;
                                      });
                                      print(verificationFailed.code);
                                    },
                                    forceResendingToken: widget.resendToken,
                                    codeSent: (verificationID, resendingToken) async {
                                      setState(() {
                                        showLoading = false;
                                        _isButtonDisabled = true;
                                        //currentState = LoginScreen.SHOW_OTP_FORM_WIDGET;
                                        this.verificationID = verificationID;
                                      });
                                    },
                                    codeAutoRetrievalTimeout:
                                        (verificationID) async {});}

当点击重新发送OTP再次请求时,仍然会收到与之前相同的OTP,因此可以决定是否过期或为什么总是得到相同的OTP,直到清除该高速缓存。请帮帮忙

ctehm74n

ctehm74n1#

Firebase发送3次相同的SMS代码,然后将其更改为不同的代码。

相关问题