【问题标题】:Cloud Firestore security rules - single protected field in a documentCloud Firestore 安全规则 - 文档中的单个受保护字段
【发布时间】:2018-06-03 23:01:28
【问题描述】:
我想在 user 文档中拥有一个名为 suspendedProfile 的只读属性,其中包含当前登录用户具有读/写访问权限的所有其他属性。有没有办法用一个简单的安全规则来做到这一点?
我想到了两个解决方案:
- 禁止修改属性的写入,例如
allow write: if request.resource.data.suspendedProfile == null;
-
/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