title: Firebase admin: list all users returns empty array
body: <p>I have an https-callable firebase cloud function to return all users as an array of their userRecords. I push each of the userRecords into an array which I later return, but it returns an empty array.</p>
  
  <p>How can I return this array to the client?</p>
  
  <p><strong>index.js:</strong></p>
  
  <pre><code>exports.listAllUsers = functions.https.onCall((data, context) =&gt; {
    // List all users
  
    return listAllUsers();
  });
  
  function listAllUsers(nextPageToken) {
    // List batch of users, 1000 at a time.
    var allUsers = [];
  
    return admin.auth().listUsers(1000, nextPageToken)
      .then(function (listUsersResult) {
        listUsersResult.users.forEach(function (userRecord) {
          // For each user
          var userData = userRecord.toJSON();
          allUsers.push(userData);
        });
        if (listUsersResult.pageToken) {
          // List next batch of users.
          console.log('Next batch of users');
  
          return listAllUsers(listUsersResult.pageToken)
        }
        else {
          // All users have been fetched
          console.log('All users have been fetched');
  
          return allUsers
        }
      })
      .catch(function (error) {
        console.log("Error listing users:", error);
      });
  
  }
  </code></pre>
  
  <p><strong>Client side</strong></p>
  
  <pre><code>const listAllUsers = this.afFunctions.httpsCallable('listAllUsers');
      listAllUsers({}).toPromise()
        .then(function (result) {
          console.log(result);
        });
    }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fXlWs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fXlWs.png" alt="Empty array is returned"></a></p>