-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
34 lines (31 loc) · 900 Bytes
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Promise = require("bluebird");
exports.objectToArray = (stats) => {
return Object.keys(stats).map(key => ({
key: key, value: stats[key]
}));
}
/**
*
* @param admin
* @param users
* @param nextPageToken
* @returns {Promise<admin.auth.ListUsersResult>}
*/
function listAllUsers(admin, users, nextPageToken) {
// List batch of users, 1000 at a time.;
return admin.auth().listUsers(1000, nextPageToken).then(function (listUsersResult) {
listUsersResult.users.forEach(function (userRecord) {
// console.log("user", userRecord.toJSON());
users.push(userRecord.toJSON());
});
if (listUsersResult.pageToken) {
// List next batch of users.
return listAllUsers(admin, users, listUsersResult.pageToken);
} else {
return Promise.resolve(users);
}
}).catch(function (error) {
console.log("Error listing users:", error);
});
}
exports.listAllUsers = listAllUsers;