0

I am trying to retrieve the Firebase users in a project. I can retrieve them, but the main program never ends. I debug using VS Code or run the script with npm run and it gets stuck both ways. In VS Code there is nothing left on the stack...it just never stops

**Users function (It returns the users without a problem)

admin.auth().listUsers returns a listUsersResult object with properties nextPageToken and a users array

const BATCH_SIZE = 2;

const listAllUsers = async (nextPageToken = undefined) => {
  let listUsersResult = await admin.auth().listUsers(BATCH_SIZE, nextPageToken);

  if (listUsersResult.pageToken) {
    return listUsersResult.users.concat(await listAllUsers(listUsersResult.pageToken));
  } else {
    return listUsersResult.users;
  }
};

Main Routine (this is the one that gets stuck)

const uploadUsersMain = async () => {
  try {

    // if I comment out this call, then there is no problem
    let firestoreUsers = await listAllUsers();
  } catch(error) {
   log.error(`Unable to retrieve users ${error}`)
}
finally {
    // do stuff
  }
}

uploadUsersMain();

What could be the issue that stops the main program from ending? What should I look for? Thanks

2
  • Never mind the recursion, how does it behave if you make just a single API request? stackoverflow.com/questions/37357080/… Commented May 24, 2019 at 1:37
  • Thanks Josh. I just limited the function to call admin.auth().listUsers(BATCH_SIZE, nextPageToken) and checked the result. I do get the desired values back but the main function keeps getting stucked. The returned value is an Object..no promise or anything. What is wrong? What can I check? It has to do definitely with the way I am calling the Promise, but I am a bit at lost on what to check. Thanks Commented May 24, 2019 at 2:35

1 Answer 1

2

To shut down your script you should use

await admin.app().delete();

Node.js will quietly stay running as long as there are handles, which can really be anything — a network socket certainly.

You could also use process.exit(), but it's good practice to properly shut down the SDK, instead of exiting abruptly when it might not be finished.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Josh! That was the solution. Thanks for your help Firebase has all these small examples, but not a single real example :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.