How to get all users having custom claim as admin/moderator using firebase admin?

Viewed 721

I want to send welcome message to all admins of my user database. Is there any method in firebase so that I can get list of all users with their custom claim as admin set to be true.

admin.auth().getUsers([
    { uid: 'uid1' },
    { email: 'user2@example.com' },
    { phoneNumber: '+15555550003' },
    { providerId: 'google.com', providerUid: 'google_uid4' },
  ])

Would above method applicable? If yes, then what parameter should I pass?

1 Answers

There is no built-in way to query Firebase Auth users based on custom claims on a user. If you want to be able to query, you would need to mirror the information into another database (like Firestore) and query that.

Otherwise, you will need to fetch every user and filter the results, which presumably is not an ideal solution.

Related