firebase / firebase/firebase-admin-node

[FR] Indexing Auth data and ListUsers with query

Open
#2,068 0 comments 2 reactions 0 assignees View on GitHub
type: feature request
Dominant language
TypeScript
Stars
1.7k
Forks
419
Avg merge
3d 10h
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**
FirebaseAuth custom claim is a great and officially recommended way to support Access Control with Rules and many features across multiple firebase modules. Yet all the auth users in firebase auth system are not distinguishable. We cannot easily control or even annotate user

Simplest use case is, we might have privilege system with firebase auth's custom claims as suggest in https://firebase.google.com/docs/auth/admin/custom-claims. But then we might want to list all the admin in our system. We need to create table for storing duplicate auth data in firestore that need to be perfectly sync with auth system just for indexing auth claims

**Describe the solution you'd like**
`listUsers` api should have more functionality. Especially filter or query by custom claims and provider (and the lack of, if possible). So we can list and manage specific users

```js
var maxResult = 100;
var allAdmins = await firebaseAdmin.auth().listUsers(maxResult,{ "claims.admin": { "equal": true } },pageToken);

var allPrivilegeUsers = await firebaseAdmin.auth().listUsers(maxResult,{ "claims.level": { "greaterThanOrEqual": 2 } },pageToken);

var allUserWithClaims = await firebaseAdmin.auth().listUsers(maxResult,{ "claims": { "greaterThan": null } },pageToken);

var allFacebookUsers = await firebaseAdmin.auth().listUsers(maxResult,{ "providers.`facebook.com`": { "greaterThan": null } },pageToken);
```

I think firestore query is the most familiar and sensible which should be available

**Describe alternatives you've considered**
Making firestore data working across storage and functions maybe? We can skip setting custom claims to user and use only firestore collection in storage and datastore rules, claims will then be used only in custom token for temporary session

**Additional context**
I don't even know the order of `listUsers` api will return back. Is it ordered by creation times? Is the last user would be returned in the last batch? I wish there would be filter by creation time such as

```js
var maxResult = 100;
var year2021 = new Date("2021-01-01");
var year2023 = new Date("2023-01-01");
var result = await firebaseAdmin.auth().listUsers(maxResult,{ createdAfter: year2021,createdBefore: year2023 },pageToken);
```

Also it should have option to orderby ascending and descending if the `listUsers` was sorted by its creation time. All of these would also let us manage user's data in firestore and datastore a lot more easier

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.