Firebase Admin SDK身份验证错误"TOO_MANY_ATTEMPTS_TRY_LATER" [英] Firebase Admin SDK Auth error "TOO_MANY_ATTEMPTS_TRY_LATER"

查看:1186
本文介绍了Firebase Admin SDK身份验证错误"TOO_MANY_ATTEMPTS_TRY_LATER"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在云函数中使用firebase admin sdk,尝试通过uid获取用户时,在某些执行中随机出错.

I'm using firebase admin sdk in my cloud functions and I'm getting error randomly in some executions when trying to get a user by uid .

let userRecord = await admin.auth().getUser(userId);

错误详细信息是:

{"error":{"code":400,"message":"TOO_MANY_ATTEMPTS_TRY_LATER",
 "errors":[{ "message":"TOO_MANY_ATTEMPTS_TRY_LATER",
             "domain":"global","reason":"invalid"}]
 }
}

我的云功能在实时数据库write上执行,并且可以为多个用户触发.总的来说,我在一次执行中有4个auth函数调用,第一个是上述调用,第二个调用是通过uidemail再次获得用户,第三个调用是generateEmailVerificationLink,最后一个调用是generatePasswordResetLink.

My cloud function executes on a real time database write and can be triggered for multiple users. In total I have 4 auth function calls in one execution first is the above one, second call is to again get user by uid or email, third call is generateEmailVerificationLink and the last call is generatePasswordResetLink.

我已经在auth的文档中检查了速率限制,但是没有提及这些操作的速率限制.另外,错误TOO_MANY_ATTEMPTS_TRY_LATER仅在REST API中提到,用于使用电子邮件密码进行注册.

I have checked the rate limits in documentation for auth but there is no mention of rate limit for these operation. Also the error TOO_MANY_ATTEMPTS_TRY_LATER was only mentioned in REST API for sign up with email password.

如果此错误是由于速率限制引起的,那么鉴于这4个调用对于数据库写入所需的操作是必需的,我应如何更改以防止此错误?

If this error is due to rate limit what should I change to prevent this error given these 4 calls are necessary for the operation needed on database write?.

我已经确定了引发过多尝试错误的实际呼叫.多次调用时,调用auth().generateEmailVerificationLink()auth().generatePasswordResetLink()会引发此错误.

I have identified the actual call which is throwing too many attempts error. The calls auth().generateEmailVerificationLink() and auth().generatePasswordResetLink() throw this error when called too many times.

我以100次迭代的方式调用了这两个循环,并等待了promise.第一次执行完成,没有任何错误,即200个请求.但是,在第一个执行结束后立即开始第二个执行将引发过多尝试的错误.所以我认为这两个电话是有限制的.现在,我试图减少这些调用并重用链接信息.像getUserByEmail这样的其他调用也可以正常工作.

I called these two in loop with 100 iterations and waited for the promises. The first executions finishes without any errors i.e. 200 requests. But starting second execution as soon as the first one ends will throw the error of too many attempts. So I think these two calls have limit. Now I'm trying to reduce these calls and reuse the link information. Other calls like getUserByEmail works fine.

let promises = [];
let auth = admin.auth();
let hrstart = process.hrtime()
for (let i = 0; i < 100; i++) {
    promises.push(auth.getUserByEmail("user email"));
    promises.push(auth.generateEmailVerificationLink("user email", {url: `https://app.firebaseapp.com/path`}));
    promises.push(auth.generatePasswordResetLink("user email", {url: `https://app.firebaseapp.com/path`}));

}

Promise.all(promises)
    .then(value => {
        let hrend = process.hrtime(hrstart);
        console.log(hrend);
        // console.log(value)
    });

推荐答案

该错误专门发生在操作auth.createEmailLink中.此功能有以下限制: 20QPS/IP地址,其中QPS是(每秒查询).可以通过将用例提交给Firebase来增加此限制.

The error was specifically in the operation auth.createEmailLink. This function has following limit: 20QPS/I.P address where QPS is (query per second). This limit can be increased by submitting the use case to Firebase.

提交问题后,我从Firebase支持部门获得了此信息.

I got this information from firebase support after submitting my issue.

链接到我的github问题: https://github.com/firebase /firebase-admin-node/issues/458

Link to my github issue: https://github.com/firebase/firebase-admin-node/issues/458

这篇关于Firebase Admin SDK身份验证错误"TOO_MANY_ATTEMPTS_TRY_LATER"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆