I have a custom claim "admin" attached to each user, carrying a boolean. Now, in my frontend i am trying to generate a list of all admins. For that i need to access all users who have said custom claim set to "true" and put them in an array, which i can then generate the list from. The array should just look like the following:
const admins = ref([
{
uid: *uid of admin1*,
name: *name of admin1*,
},
{
uid: *uid of admin2*,
name: *name of admin2*,
},
...
])
So the following problems arise:
- How do i access all users with said custom claim set to true, so that i can loop over them and populate my array?
- Is this a case for a cloud function, so that it can not be manipulated?
I tried reading this Firebase documentation, however i could not make sense of it.
CodePudding user response:
How do i access all users with said custom claim set to true, so that i can loop over them and populate my array?
There is no direct way to query users based on custom claims.
Is this a case for a cloud function?
Yes, you would have to list all users as in the documentation that you've shared and check for custom claims for each user separately.
It might be best to use a database like Firestore or Realtime Database and maintain a collection of all admins. Make sure this cannot be updated from client side directly using security rules.