【问题标题】:Return specific properties from Firestore object for different users?从 Firestore 对象返回不同用户的特定属性?
【发布时间】:2022-01-20 19:08:49
【问题描述】:

我的 Firestore 中有以下用户对象:

User {
    email: String
    firstName: String
    lastName: String
    preferredName: String
}

我有以下要求:

如果获取的user id等于获取者的user id(正在获取的人),则返回所有字段,否则只返回获取的用户的firstNamelastName

这是我目前在 Firebase 中的规则,不幸的是,它完全阻止了对用户的访问:

// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /users/{userId} {
    allow read, update, delete: if request.auth != null && request.auth.uid == userId;
}

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-authentication firebase-security acl


    【解决方案1】:

    安全规则允许在文档级别进行读取访问。

    无法使用它们来过滤从文档本身返回的数据。如果需要,请考虑创建两个集合:一个包含公共数据,一个包含私有数据。

    【讨论】:

    • 这似乎是一种反模式。您是否有理由不能按字段进行操作?
    • 什么看起来像是反模式?
    猜你喜欢
    • 2022-01-01
    • 2012-07-19
    • 2021-09-10
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2015-10-21
    • 1970-01-01
    相关资源
    最近更新 更多