List users via firebase admin SDK

590 views
Skip to first unread message

Maik Mewes

unread,
Sep 13, 2018, 10:56:55 AM9/13/18
to Firebase Google Group
In my FB app I'm using anonymous auth. In the firebase console, I see 50+ users in the auth section. When I use the admin SDK listUsers() function exactly the way it is suggested in the documentation, I only get a list of 12-15.

Can anybody explain where the difference comes from. And, if it is the proper behaviour (think of only active users) how can the console view be cleaned up?

Kiana McNellis

unread,
Sep 18, 2018, 5:40:05 PM9/18/18
to fireba...@googlegroups.com
Both the console and admin SDK should be showing the same users.  Are you following the code sample here (and setting maxResults to a number greater than 50)?  

Another step to try is using the CLI's auth:export functionality to download the full list of users.

On Thu, Sep 13, 2018 at 7:56 AM Maik Mewes <maikmde...@gmail.com> wrote:
In my FB app I'm using anonymous auth. In the firebase console, I see 50+ users in the auth section. When I use the admin SDK listUsers() function exactly the way it is suggested in the documentation, I only get a list of 12-15.

Can anybody explain where the difference comes from. And, if it is the proper behaviour (think of only active users) how can the console view be cleaned up?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/639d0dc7-8d91-499d-b53a-4a5eeb88ee7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maik Mewes

unread,
Sep 19, 2018, 10:20:30 AM9/19/18
to fireba...@googlegroups.com
I am using that code converted to Typescript. CLI export is showing all 49 users in the project, whereas my cloud function gives me 18 users.


My code:
exports.userTester = functions.firestore.document ('tests/{id}').onWrite(async (snap, ctx) => {
if (!snap.after.exists) {
console.log ("Snapshot was deleted - no handling needed");
return;
}
const data = snap.after.data ();
data ['read'] = false;
//data ['timestamp'] = new Date ();
const token = new Date().toDateString ();
await writeTestToAllUsers (data, token);
});

async function writeTestToAllUsers(data : admin.firestore.DocumentData, nextPageToken : string) {
console.log ("writetoAllUsers");
// find all active users
await admin.auth ().listUsers (1000, nextPageToken).then (async userList => {
console.log ("Got user batch with size " + userList.users.length);
userList.users.forEach (async user => await writeTestToUser (user, data));
if (userList.pageToken) {
await writeTestToAllUsers (data, userList.pageToken);
}
}).catch (err => {
console.log (err);
});
};

async function writeTestToUser (user:admin.auth.UserRecord, data : admin.firestore.DocumentData) {
console.log (user.uid);
};

gives me the following output:
image.png


You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/ihFdf-N_hfw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Kiana McNellis

unread,
Sep 19, 2018, 6:16:02 PM9/19/18
to fireba...@googlegroups.com
Thats odd.  Would you mind submitting a support case so that we can look into your specific project?

Thanks,
Kiana

Maik Mewes

unread,
Sep 20, 2018, 10:21:22 AM9/20/18
to fireba...@googlegroups.com
Opened an issue: 8-7223000023377 .

Thanks for your help. 


Reply all
Reply to author
Forward
0 new messages