基于Firebase角色的访问

基于Firebase角色的访问,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我想限制写入某些文档的访问权限。 因此,我创建了一个“administrators”集合,它使用用户的UID作为文档UID,并使用属性“admin”来检查值 我当前尝试实现的数据库规则如下: match /approved-posts/{post} { allow read: if true allow write: if get(/databases/$(database)/documents/administrators/$(request.auth.ui

我想限制写入某些文档的访问权限。 因此,我创建了一个“administrators”集合,它使用用户的UID作为文档UID,并使用属性“admin”来检查值

我当前尝试实现的数据库规则如下:

  match /approved-posts/{post} {
        allow read: if true
        allow write: if get(/databases/$(database)/documents/administrators/$(request.auth.uid)).data.admin == true
  }
我的uid是:uYdyhMBAgyZ36ZNF5B2iPb0NdxQ2

因此,我在firebase拥有以下收藏:

但不知何故,当我尝试创建一个新帖子时,我得到了以下错误:

FirebaseError: Missing or insufficient permissions.
    at new FirestoreError (http://localhost:4200/vendor.js:158627:28)
我做错了什么

在行尾添加分号(例如允许读取:if true;)没有帮助

使用模拟器时,我得到一个空值错误:

我阅读并尝试了一个更简单的规则。但我还是犯了一个错误。


是否有任何可能需要打开的设置?

您的规则看起来很好,但在读写规则末尾缺少分号,不确定这是否是解决方案,但请尝试添加分号并更新规则

  match /approved-posts/{post} {
        allow read: if true;
        allow write: if get(/databases/$(database)/documents/administrators/$(request.auth.uid)).data.admin == true;
  }
哦,不,我的UID是假的。 它一开始有一个空间。所以我有一个复制粘贴错误

因为仪表板上的装饰,我没有注意到。只有在我用UID重新创建了一个没有前导空格的文档之后,它才能正常工作

感谢您迄今为止的帮助:)