firebase / firebase/firebase-admin-node

[FR] Indexing Auth data and ListUsers with query

未关闭
#2,068 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
type: feature request
主要语言
TypeScript
星标
1.7k
派生
419
平均合并
3 天 10 小时
30 天内合并 PR
16

描述

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

贡献指南

打开贡献指南

调研方向

从 Admin Auth listUsers API 及其当前的分页和排序行为开始。在确定实现和测试之前,明确支持的查询字段、比较运算符、按 provider 和 custom-claim 过滤、创建时间范围以及排序要求;当约定的查询能够与分页一致地工作时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
nodejs, typescript
领域
api, authentication
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。