【问题标题】:Firebase auth().createUser - Error while making request: timeout of 10000ms exceedeFirebase auth().createUser - 发出请求时出错:超过 10000 毫秒的超时
【发布时间】:2019-02-28 10:41:45
【问题描述】:

我正在尝试通过 Firebase 中的特定功能包含用户列表(超过 50 个)。这是我的代码:

Object.keys(newUsers).forEach((key) => {
    console.log(newUsers[key]['name']);
    admin.auth().createUser({
        uid: key,
        email: newUsers[key]['email']
        password: newUsers[key]['InitialPwd'],
        disabled: false,
        emailVerified: false,
        displayName: newUsers[key]['name'],
    }).then((userRecord) => {
        return console.log('Success');
    }).catch(function(error) {
        console.log("Error:", error);
    });                    
});

错误是(对于每条记录):

{ 错误:发出请求时出错:超过 10000 毫秒的超时。 在 FirebaseAppError.FirebaseError [作为构造函数] (/srv/node_modules/firebase-admin/lib/utils/error.js:39:28) 在 FirebaseAppError.PrefixedFirebaseError [作为构造函数] (/srv/node_modules/firebase-admin/lib/utils/error.js:85:28) 在新的 FirebaseAppError (/srv/node_modules/firebase-admin/lib/utils/error.js:119:28) 在 /srv/node_modules/firebase-admin/lib/utils/api-request.js:117:23 在 在 process._tickDomainCallback (internal/process/next_tick.js:228:7) 错误信息:{代码: '应用程序/网络超时', 消息:“发出请求时出错:超过 10000 毫秒的超时。” }, codePrefix: 'app' }

我该如何解决这个问题?

【问题讨论】:

  • 如果只创建一个用户会出现这个问题吗?
  • 嗨,@Jen,它不会出现在一个或一个简短的列表中。在一些测试中,我发现当我有超过 50 个新用户时会发生这种情况
  • 啊,好的,这是个好信息。您是在云函数中运行它吗?
  • 是的@JenPerson。此 Cloud Function 在用户上传 CSV 文件以导入新客户端时启动。需要使用“初始密码”创建用户

标签: firebase firebase-authentication


【解决方案1】:

Cloud Functions 设置为在短时间内运行。如果您在云函数中做大量工作,它可能会在完成之前超时。我建议有一些解决方案:

1.更改您的 Cloud Functions 超时。在Cloud console 中,检查顶部以确保选择了您当前的项目,然后在中间您将找到您的功能列表。点击你的功能。您现在应该了解功能详细信息。点击“编辑”。 “保存”按钮正上方是“更多”。选择“更多”,您将看到增加超时的选项。这可以修改函数保持活动的时间。

2.更改批量大小,以便一次创建更少的用户。

3.确保您的承诺按预期工作。如果您不将调用返回给createUser,则生成的UserRecord 将无法访问。

Object.keys(newUsers).forEach((key) => {
    console.log(newUsers[key]['name']);
    return admin.auth().createUser({
        uid: key,
        email: newUsers[key]['email']
        password: newUsers[key]['InitialPwd'],
        disabled: false,
        emailVerified: false,
        displayName: newUsers[key]['name'],
     }).then((userRecord) => {
        return console.log('Success');
     }).catch(function(error) {
        console.log("Error:", error);
     });                    
  });

4.我对这一点可能不正确,但似乎用户是一个接一个创建的,而不是同时创建的。这可能是研究使用 Promise.all 的好案例,这样所有用户都可以同时创建,而不是等待一个用户完成后再开始下一个用户。

【讨论】:

  • 没有这样的东西了Change your Cloud Functions timeout
  • @ggDeGreat 是的,有。我刚刚检查过。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 2022-07-25
  • 1970-01-01
  • 2021-11-14
相关资源
最近更新 更多