【问题标题】:How to block users using Firebase as a backend?如何阻止使用 Firebase 作为后端的用户?
【发布时间】:2020-03-02 14:26:55
【问题描述】:

试图让用户屏蔽其他用户。屏蔽含义:来自被屏蔽用户的帖子将不再显示在提要中。

Firebase 数据库:

/databaseRoot
    /userId1
       blockeduserId1 : true
       blockeduserId2 : true
   /posts
       childByAutoId1 :  //users data
       childByAutoId2 :  //users data

我在 Firebase 数据库中设置了如下规则:

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {

    "posts": {
      ".read": true,
      ".write": true
    },

      "users": {
        "$user_id":{
              ".read": "!root.child('blocked/'+$user_id+'/'+auth.uid+'/true').exists()",
                        ".write": true
        }
      }

  }
}

问题:上面的代码只是阻止了被阻止的用户阅读任何帖子。 IE。不仅仅是过滤掉被阻止的用户。关于这个问题的任何指针?

【问题讨论】:

    标签: firebase-realtime-database firebase-security


    【解决方案1】:

    根据文档,rules are not filters。您不能使用规则来更改查询的结果集。查询要么能够获得每个匹配的孩子,要么被拒绝。规则不会评估每个子节点的规则以确定是否应将其发送回客户端。

    如果你想限制查询的结果,查询应该有一个过滤器,只请求符合某些条件的子项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-17
      • 2016-10-20
      • 1970-01-01
      • 2020-02-07
      • 2021-02-22
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多