firebase / firebase/firebase-admin-node

[FR] Indexing Auth data and ListUsers with query

Abierto
#2,068 0 comentarios 2 reacciones 0 asignados Ver en GitHub
type: feature request
Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
3 d 10 h
PR fusionados (30 d)
16

Descripción

**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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.