【问题标题】:Cloud Firestore security rules - single protected field in a documentCloud Firestore 安全规则 - 文档中的单个受保护字段
【发布时间】:2018-06-03 23:01:28
【问题描述】:

我想在 user 文档中拥有一个名为 suspendedProfile 的只读属性,其中包含当前登录用户具有读/写访问权限的所有其他属性。有没有办法用一个简单的安全规则来做到这一点?

我想到了两个解决方案:

  1. 禁止修改属性的写入,例如allow write: if request.resource.data.suspendedProfile == null;
  2. /secure 集合,allow read;user 文档中

我认为第一个选项更好,所有与用户相关的属性都在一个文档中,但我很想听听您的想法。有没有其他更简单的方法来实现这一点?

【问题讨论】:

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


    【解决方案1】:

    我想我设法为自己的答案找到了解决方案using Firebase documentation

    // A user can update a product reviews, but they can't change
    // the headline.
    // Also, they should only be able up update their own product review,
    // and they still have to list themselves as an author
    allow update: if request.resource.data.headline == resource.data.headline
                        && resource.data.authorID == request.auth.userID
                        && request.resource.data.authorID == request.auth.userID;
    

    所以在我的情况下,我只会allow update: if request.resource.data.suspendedProfile == resource.data.suspendedProfile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      相关资源
      最近更新 更多