FireStore:查询Firebase Auth表? [英] FireStore: query the Firebase Auth table?

查看:73
本文介绍了FireStore:查询Firebase Auth表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firestore构建应用程序,一群人需要能够访问该对象,并且按照

I'm building an app using Firestore, where a group of people need to be able to access an object, and I followed the guide at https://firebase.google.com/docs/firestore/solutions/role-based-access. So, my object looks a little bit like this:

{
  title: "A Great Story",
  content: "Once upon a time ...",
  members: {
    alice: "host",
    bob: "player",
    david: "player",
    jane: "player"
  }
}

members中的那些键只是用户UID,因此实际上它们看起来并不那么好:)

Those keys in members are simply User UID's, so in reality they don't look quite as nice of course :)

现在,一切正常,我可以查询当前登录用户所属的对象,所有规则均有效.但是,现在我想显示我的应用程序中的成员列表.如何查询会员地图中的用户的Firebase Auth系统?

Now, this all works fine, I can query objects that the currently logged in user is a member of, all the rules are working and stuff. But, now I want to show the list of members in my app. How can I query the Firebase Auth system for the users in my members map?

如果这不可能,那么解决此问题的正常"方法是什么?在文档本身中是否有用户信息的副本(名称,电子邮件,个人资料图片)?但是,您如何处理用户更改自己的任何信息?然后文档中有陈旧的旧数据.

And if that is not possible, what is the "normal" way to solve this? Have a copy of the user information (name, email, profile picture) in the document itself? But how do you handle a user changing any of own info? Then the document has stale old data..

我来自传统的关系数据库世界,这是我使用NoSQL数据库/Firestore的第一步,因此我不清楚如何最好地构造用户数据并使其保持最新状态.

I'm coming from a traditional relational database world, these are my first steps with a NoSQL database / Firestore, so it's not really clear to me how to best structure my user data and keep it up to date.

推荐答案

使用客户端SDK,无法列出Firebase项目的所有用户.

With the client SDKs there is no way to list all the users of your Firebase project.

另一方面,Admin SDK允许批量检索整个用户列表,请参见 https://firebase.google.com/docs/auth/admin/manage-users#list_all_users .请注意,如果您想使用Admin SDK提供的这种功能,则需要在特权环境"中进行操作(请参见 https://firebase.google.com/docs/admin/setup ),例如使用云功能.然后,您需要从前端调用此Cloud Function.

On the other hand, the Admin SDK allows retrieving the entire list of users in batches, see https://firebase.google.com/docs/auth/admin/manage-users#list_all_users. Note that if you want to use this possibility offered by the Admin SDK, you need to do it from a "privileged environment" (see https://firebase.google.com/docs/admin/setup), for example with a Cloud Function. You would then need, from you front-end, to call this Cloud Function.

但是,经典方法之一是在专用的Cloud Firestore集合中维护所有用户的列表.这种方法有很多优点,其中:

However, one of the classical approach is to maintain a list of all your users in a dedicated Cloud Firestore collection. There are several advantages with this approach, among which:

  • 您可以使用客户端SDK轻松查询此列表;
  • 您可以在用户个人资料文档中存储一些其他信息,例如用户角色.实际上,使用Admin SDK的listUsers()方法,您得到的结果为 UserRecord 对象,该对象具有固定的属性列表.
  • You can easily query this list with the client SDKs;
  • You can store some extra info in the user profiles document, e.g. the user roles. As a matter of fact, with the Admin SDK's listUsers() method you get the result as UserRecord object which has a fixed list of properties.

这篇关于FireStore:查询Firebase Auth表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆