Jainam Jhaveri
Jainam Jhaveri

Reputation: 1561

List firebase auth users using specific params using node.js admin sdk

Is there a way to list a subset of users by passing specific params using the firebase admin sdk? For example, I want to list the first 100 users whose metadata.lastSignInTime < specific time stamp.

Currently, I could only find admin.auth().listUsers() in the docs which doesn't have any param to perform user query.

We can fetch all the users and then perform query locally, but this would be an overkill if my project contains a million users

Upvotes: 4

Views: 1317

Answers (2)

Yan Zhuk
Yan Zhuk

Reputation: 23

I had a similar problem. I not only add the user, but also add information about him to a separate collection in Realtime database.

    return new Promise((resolve, reject) => {

            if (docRef === undefined) {

                auth.createUserWithEmailAndPassword(item.login, item.pass)
                    .then((res) => {

                        delete item.pass;
                        docRef = colRef.doc(res.user.uid);

                        docRef.set({
                            name:item.name,
                            login:item.login,
                            info:item.info
                        });

                        return resolve();

                    })
                    .catch(error => {
                        return reject(error);
                    });

            } else {

                return resolve();
            }

And them you limit data using. https://firebase.google.com/docs/firestore/query-data/order-limit-data and https://firebase.google.com/docs/firestore/query-data/query-cursors

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 598926

The Firebase Admin API for listing all users returns a limited-but-unfiltered list of users from Firebase Authentication. There is no way to pass additional conditions to the Admin SDK.

If you need more advanced query capabilities for lists of users, consider storing additional user profiles in a separate database for querying. For example, it is quite common to have a list of users in the Realtime Database or Cloud Firestore to simplify querying them (and also make them accessible from the app).

Upvotes: 1

Related Questions