问题
We're using Custom Claims in Firebase Auth to manage access in Firebase and allow custom UI experience.
We're now working on the User Admin part and we can't find a way to retrieve users by the custom claims.
For example, a user belongs to an organization and have different access level - admin or user. We need to allow the organization's admin to see all their organization's users.
We'd like to avoid using a separate database to manage organization users to not double up the data.
Is it possible? Can we retrieve all Auth users while filtering them by specific Custom Claim?
Thanks!
回答1:
There is no built-in API to get a list of all users that have a specific claim.
There is an API to get a list of all users in the Admin SDK. So you could use that and then filter the users that have the claim you're looking for.
But performance of this will not be spectacular. So if listing all users with a specific claim is a common use-case for your app, you'll want to reconsider your concern about using an additional place to store the data. Duplicating data to achieve (well performing) use-cases is quite common in NoSQL.
来源:https://stackoverflow.com/questions/52902483/firebase-auth-list-of-users-by-custom-claims