Is there a way to get all the users' count in firebase? (authenticated via password, facebook, twitter, etc.) Total of all social and email&password authenticated users.
I stumbled on this question and wanted to share three methods to get total number of signed-up users.
Go to the console, under Authentication tab, you can directly read the number of users under the list of users:
56 users! yay!
For programmatic access to the number of users with potential filter on provider type, registration date, last connection date... you can write a script leveraging listUsers from the admin SDK.
For example, to count users registered since March 16:
const admin = require("firebase-admin");
const serviceAccount = require("./path/to/serviceAccountKey.json");
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
async function countUsers(count, nextPageToken) {
const listUsersResult = await admin.auth().listUsers(1000, nextPageToken);
listUsersResult.users.map(user => {
if (new Date(user.metadata.creationTime) > new Date("2021-03-16T00:00:00")) {
count++;
}
});
if (listUsersResult.pageToken) {
count = await countUsers(count, listUsersResult.pageToken);
}
return count;
}
countUsers(0).then(count => console.log("total: ", count));
Your app maybe already stores user documents in Firestore, or the Realtime Database, or any other database. You can count these records to get the total number of registered users. (If you use Firestore, you can read my article on how to count documents)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With