-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.js
28 lines (24 loc) · 747 Bytes
/
list.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
'use strict';
const admin = require('./firebase-admin');
module.exports.list = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
// Start listing users from the beginning, 1000 at a time.
listAllUsers().then(function(listUsersResult) {
callback(null, {
statusCode: 200,
body: JSON.stringify(listUsersResult.users),
});
})
.catch(function(error) {
console.log('Error listing users:', error);
callback(null, {
statusCode: 501,
headers: { 'Content-Type': 'text/plain' },
body: 'Couldn\'t list the users',
});
});
};
function listAllUsers(nextPageToken) {
// List batch of users, 1000 at a time.
return admin.auth().listUsers(1000, nextPageToken);
}