Cloud Firestore安全规则 - 文档中的单个受保护字段

问题描述 投票:4回答:1

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

我想到了两个解决方案:

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

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

firebase firebase-security google-cloud-firestore
1个回答
5
投票

我想我找到了自己的答案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

© www.soinside.com 2019 - 2024. All rights reserved.