To get all the users from auth in Firebase, you can use the Admin SDK for Firebase.
It gives you elevated privileges to perform operations in the system that a normal user can not. The Admin SDK comes with a lot of functionality built-in. But, the one thing that we care about here is Managing Users.
Initialize a project in Firebase using the firebase-tools on your PC.
$ mkdir firebase-users && cd firebase-users
index.js, write the following code:
const functions = require('firebase-functions');
auth.listUsers() is the function which returns a
Promise with the
userRecords object. It takes in two optional arguments.
maxResults(optional): the number of users to get. Defaults to
uidof the user up to whom the results were fetched in the previous iteration of the function. This one is only useful if you are recursively calling the
auth.listUsers()method to get more than
1000users at a time from Firebase auth.
You can hit the endpoint using
curl as follows:
In your console, you will get the following response
This response is for a single user because the argument
maxResults was set to
1. When you have multiple users in auth, you will get a larger
Here, we are not sending the
userRecords to the clients in the response. This is because that is probably sensitive data in most cases. Instead, we are using
console.log() to print each
userRecord in the
Of course, you can perform whatever operations inside the cloud function after receiving the
userRecords from Firebase auth.