【问题标题】:How to use the forceResendingToken in firebase phone auth in flutter to resend the otp如何在flutter中使用firebase电话身份验证中的forceResendingToken重新发送otp
【发布时间】:2019-01-06 12:40:53
【问题描述】:

我正在寻找一种方法来重新发送 OTP 在 firebase verifyPhoneNumber in flutter。 我已经浏览了关于 phoneAuth 的example,但找不到重新发送 OTP 的方法。 有 forceResendingToken 的选项

final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      this.verificationId = verificationId;
      _smsCodeController.text = testSmsCode;
    };


await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: this._phone,
        codeAutoRetrievalTimeout: autoRetrieval,
        codeSent: smsCodeSent,
        forceResendingToken: ,//how to get this token
        timeout: const Duration(seconds: 40),
        verificationCompleted: verifSuccessful,
        verificationFailed: verifFailed);
  }

如何使用此令牌重新发送 OTP。

【问题讨论】:

    标签: firebase dart flutter firebase-authentication


    【解决方案1】:

    来自Firebase reference documentation

    onCodeSent(String, PhoneAuthProvider.ForceResendingToken) callback获取的ForceResendingToken在自动检索超时前强制重新发送另一条验证短信。

    所以在您的情况下,这将是 verifyPhoneNumber() 调用的 PhoneCodeSent 回调。

    【讨论】:

      【解决方案2】:

      您必须从代码发送回调中记录 resendToken 的值并将其传递给 forceresendingtoken。此外,内置的超时持续时间是 30 秒,因此请确保在超时秒后点击重新发送按钮,您可以使用 timerbutton 包,在这种情况下非常方便。

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

      String _verificationId = "";
      int? _resendToken;
      
      Future<bool> sendOTP({required String phone}) async {
        await FirebaseAuth.instance.verifyPhoneNumber(
          phoneNumber: phone,
          verificationCompleted: (PhoneAuthCredential credential) {},
          verificationFailed: (FirebaseAuthException e) {},
          codeSent: (String verificationId, int? resendToken) async {
          _verificationId = verificationId;
          _resendToken = resendToken;
          },
          timeout: const Duration(seconds: 25),
          forceResendingToken: _resendToken,
          codeAutoRetrievalTimeout: (String verificationId) {
          verificationId = _verificationId;
        },
       );
       debugPrint("_verificationId: $_verificationId");
       return true;
      }
      

      【讨论】:

        猜你喜欢
        • 2020-07-22
        • 2021-05-03
        • 2021-06-27
        • 2021-07-13
        • 2021-03-29
        • 2019-01-13
        • 2021-02-12
        • 2021-06-10
        • 2019-12-01
        相关资源
        最近更新 更多