【问题标题】:How to add OTP expire time in flutter with firebase Phone Auth如何使用firebase电话身份验证添加OTP过期时间
【发布时间】:2021-10-02 02:07:34
【问题描述】:
 await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: mobile,
        timeout: const Duration(seconds: 5),
        verificationCompleted: verificationCompleted,
        verificationFailed: verificationFailed,
        codeSent: codeSent,
    );

我正在使用这个 sn-p,但这里提到的超时是针对 autoOtpRetrievelTimeOut 但我正在寻找如何添加 otp 过期时间,比如 60 秒后我希望用户再次单击重新发送 OTP

【问题讨论】:

    标签: firebase flutter


    【解决方案1】:
     bool isTimeExpired = false;    
    
       Future.delayed(const Duration(seconds: 60), () {
          setState(() { //Replace setState with your state management
            // Enable Resend Option
            isTimeExpired = true;
          });
        
        });
    
    await FirebaseAuth.instance.verifyPhoneNumber(
            phoneNumber: mobile,
            timeout: const Duration(seconds: 5),
            verificationCompleted: verificationCompleted,
            verificationFailed: verificationFailed,
            codeSent: codeSent,
       );
    
    verificationCompleted(params)async{
       if(isTimeExpired){
         await FirebaseAuth.instance.signOut();
         //your code
       }
    }
    

    【讨论】:

    • 我已经完成了这一步。基本上我希望 otp 代码应该在 60 秒后过期,并且不允许用户使用过期 OTP 登录。用户将单击重新发送 OTP,他将收到新的 OTP 代码,并且在 60 秒内他可以使用新的 OTP 代码登录! T 问题是我如何为 OTP 代码添加过期时间是否有任何可用的 firebase 功能??
    • 我仍然可以使用旧 otp 登录这是主要问题 otp 时间应该从 firebase 端过期!
    • 您可以在verificationCompleted方法中从FirebaseAuth调用signOut并显示UI重新发送OTP和OTP过期!
    猜你喜欢
    • 2021-06-27
    • 2021-05-03
    • 2021-02-19
    • 2019-12-01
    • 2022-06-28
    • 2019-08-17
    • 2021-09-08
    • 2021-10-03
    • 2021-03-29
    相关资源
    最近更新 更多