Flutter Firebase auth的请求太多

发布于 2025-02-12 14:38:05 字数 971 浏览 0 评论 0原文

我正在我的flutter应用程序上构建电子邮件验证页面,以供用户在登录之前验证他们的电子邮件。 。


  Future sendVerificationEmail() async {
    try{
      final user = FirebaseAuth.instance.currentUser!;
      await user.sendEmailVerification();

      setState(() => canResendEmail = false);
      await Future.delayed(const Duration(seconds: 5));
      canResendEmail = true;

    }catch (e) {
      Utils.showSnackBar(e.toString());
    }
  }

...............................

ElevatedButton.icon(
          icon: const Icon(Icons.email, size: 32),
            label: const Text("Resend email"
            ),
            onPressed: canResendEmail ? sendVerificationEmail : null,
        ),

但是,问题是当我尝试再次重新发送电子邮件时,大多数时候我会收到错误的错误:

[firebase-auth/太多请求]由于异常活动,我们已经阻止了该设备的所有请求。稍后再试。

好吧,我知道这非常适合安全,但根本不一致。像有时,我可以在30秒内重新发送5封电子邮件,有时会在2分钟以上显示此错误。 我的问题是,我是否可以在firebase中设置一些规则,以使我想每秒发送一定数量的电子邮件请求,或者至少想知道我需要等待的确切时间是什么而不是在这种情况下,有时我可以在短时间内发送多个请求。

I was building an email verification page on my flutter app for users to verify their emails before they can sign in. So in the verification page, I have a button that allows the users to resend the verfication email after 5 seconds from the time they sent.


  Future sendVerificationEmail() async {
    try{
      final user = FirebaseAuth.instance.currentUser!;
      await user.sendEmailVerification();

      setState(() => canResendEmail = false);
      await Future.delayed(const Duration(seconds: 5));
      canResendEmail = true;

    }catch (e) {
      Utils.showSnackBar(e.toString());
    }
  }

...............................

ElevatedButton.icon(
          icon: const Icon(Icons.email, size: 32),
            label: const Text("Resend email"
            ),
            onPressed: canResendEmail ? sendVerificationEmail : null,
        ),

But then the problem is when I try to resend the email again, most of the time i get the error which says:

[firebase-auth/too many requests] We have blocked all requests from this device due to unusual activity. Try again later.

Well, I understand that this is great for security but its just not consistent at all. Like sometimes I can resend 5 emails within 30 seconds and sometimes it will keep showing this error for more than 2 minuetes.
My question is whether i can set some rules in the firebase to make that I can like send certain number of email requests per seconds or like at least get to know what is the exact time that I need to wait before I can send a request again instead of this random situation where sometimes I can send multiple requests within short time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2025-02-19 14:38:05

我能够通过设置提供的选项来克服这一点,以在测试活动期间禁用验证检查(请参阅文档在这里)。看起来像这样:

FirebaseAuth.instance.setSettings(appVerificationDisabledForTesting: true);

I was able to get past this by setting a provided option to disable the verification check during testing activities (see documentation here). It looks like this:

FirebaseAuth.instance.setSettings(appVerificationDisabledForTesting: true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文