【问题标题】:firebase rules give privilege to firebase user ids stored in a mapfirebase 规则授予存储在地图中的 firebase 用户 ID 的权限
【发布时间】:2018-10-26 01:01:41
【问题描述】:

我想为存储在 moddores 文档中的用户 ID 提供删除权限:

以下规则允许用户删除自己的数据,但不能删除其他用户的数据:

 service cloud.firestore {
 match /databases/{database}/documents {
 match /Registros/{registroId} {
  allow read; 
  allow delete: if request.auth.uid == resource.data.userid //||request.auth.uid == resource.data.userid;
  allow create, update: if request.auth.uid != null;

}

}
}

我想为上面文档中存储的用户添加一个 OR。

如何做到这一点?

我将版主的用户 ID 存储在一个值中。这个地图怎么能在规则中访问?

【问题讨论】:

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


    【解决方案1】:

    对于任何有同样问题的人:

    找到了解决办法:

    service cloud.firestore {
    match /databases/{database}/documents {
    match /Registros/{registroId} {
        function isSignedIn() {
          return request.auth != null;
        }
        function getUser() {
          return request.auth.uid;
        }
        function isOneOfModerator(array) {
          return isSignedIn() && (getUser() in array.data.users);
        }
    
    
      allow read; 
      allow delete: if isOneOfModerator(get(/databases/$(database)/documents/Admins/moderador))
      allow create, update: if isSignedIn();
    
    }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2017-01-25
      • 1970-01-01
      • 2019-10-30
      • 2021-07-06
      • 2018-07-03
      • 2016-11-07
      • 1970-01-01
      • 2017-01-28
      相关资源
      最近更新 更多