Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase帖子评论规则_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

Firebase帖子评论规则

Firebase帖子评论规则,firebase,firebase-realtime-database,firebase-security,Firebase,Firebase Realtime Database,Firebase Security,对于类似于facebook的帖子,firebase的评论规则应该是什么 有两件事: 首先,只有经过身份验证的用户才能发表评论。 第二,只有发表评论的用户才能删除评论。已注释其id的用户保存在用户名中。 我强烈建议使用编写/编译Firebase数据库安全规则。数据结构可能变得庞大而复杂。通过使用,您将能够轻松编写复杂的访问和结构规则,这些规则可用于其他数据库模式 您的规则如下所示: path /comment/{postUid}/{commentUid} is Comment { read(

对于类似于facebook的帖子,firebase的评论规则应该是什么

有两件事: 首先,只有经过身份验证的用户才能发表评论。 第二,只有发表评论的用户才能删除评论。已注释其id的用户保存在用户名中。

我强烈建议使用编写/编译Firebase数据库安全规则。数据结构可能变得庞大而复杂。通过使用,您将能够轻松编写复杂的访问和结构规则,这些规则可用于其他数据库模式

您的规则如下所示:

path /comment/{postUid}/{commentUid} is Comment {
   read() { true }
   write() { isAuthor(this) || isAuthor(prior(this)) }
}

type Comment {
   text : String,
   username : String
}

isAuthor(value) { auth != null && value.username == auth.uid }
注意
isAuthor(在此之前))
call。这是确保只有作者才能删除评论的方法
previor
函数返回当前事件(创建、更新或删除)之前保存的数据

使用firebase bolt工具将规则编译为JSON格式后,您将获得:

{
  "rules": {
    "comment": {
      "$postUid": {
        "$commentUid": {
          ".validate": "newData.hasChildren(['text', 'username'])",
          "text": {
            ".validate": "newData.isString()"
          },
          "username": {
            ".validate": "newData.isString()"
          },
          "$other": {
            ".validate": "false"
          },
          ".read": "true",
          ".write": "auth != null && newData.child('username').val() == auth.uid || auth != null && data.child('username').val() == auth.uid"
        }
      }
    }
  }
}

你试过写什么了吗?如果是,请更新您的问题以显示。如果不是的话,请看一看我最近的照片。要防止删除,请参阅。