Firebase auth().createUser - Error while making request: timeout of 10000ms exceede

故事扮演 提交于 2020-07-09 08:19:27

问题


I'm trying to include a list of users (more than 50) through a specific function in Firebase. Here's my code:

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);
    });                    
});

And the error is (for each record):

{ Error: Error while making request: timeout of 10000ms exceeded. at FirebaseAppError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:39:28) at FirebaseAppError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:85:28) at new FirebaseAppError (/srv/node_modules/firebase-admin/lib/utils/error.js:119:28) at /srv/node_modules/firebase-admin/lib/utils/api-request.js:117:23 at at process._tickDomainCallback (internal/process/next_tick.js:228:7) errorInfo: { code: 'app/network-timeout', message: 'Error while making request: timeout of 10000ms exceeded.' }, codePrefix: 'app' }

How can I solve this?


回答1:


Cloud Functions are set to run for a short period of time. If you are doing lots of work in a Cloud Function, it may time out before it is complete. There are a few solutions to this that I would suggest:

1.Change your Cloud Functions timeout. In the Cloud console, check at the top to make sure your current project is selected, and then in the middle you'll find your list of functions. Click on your function. You should be in function details now. Click "Edit". Right above the "save" button is "more". Select "more" and you'll see an option for upping the timeout. This can modify how long the function stays alive.

2.Change the batch size so you're creating fewer users at a time.

3.Make sure your promises are working as expected. If you don't return the call to createUser, the resulting UserRecord won't be accessible.

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.I may be incorrect about this point, but it appears that the users are created one after another rather than concurrently. This could be a good case to look into using Promise.all so that all of the users can be created simultaneously, rather than waiting for one to complete before starting the next.



来源:https://stackoverflow.com/questions/52487470/firebase-auth-createuser-error-while-making-request-timeout-of-10000ms-exce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!