【问题标题】:only user can modify has own data in firebase只有用户可以修改在 Firebase 中有自己的数据
【发布时间】:2019-01-24 22:40:38
【问题描述】:

我想让只有用户能够创建新帖子,并且只有用户才能修改他们创建的帖子。喜欢删除或编辑!

数据库结构

{
  "post" : {
    "-LWzHsKzAyK9Wfa1kbD_" : {
      "name" : "test",
      "title" : "test",
      "userId" : "8D3sENaBcLaXoGNnh1MPuoyj5LP2"
    },
    "-LWzHx6u-gQ7XoVR714a" : {
      "name" : "check",
      "title" : "check",
      "userId" : "WUM2HBkGo8TFDeOjEqO1s3lCj1p1"
    }
  }
}

我使用了这个规则,但是我在保存No such method/property 'userId'.时出错

{
    "rules": {
    ".read": false,
    ".write": false,
        "report": {
        ".read": "auth != null",
        ".write": "auth != null && ( (data.exists() && data.userId === auth.uid) || !data.exists() || !newData.exists() )"
        }
    }
}

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security


    【解决方案1】:

    您不能只使用属性访问器表示法来获取数据的子值。您必须调用child() 函数来获取孩子,并调用val() 函数来获取它的值。

    所以:

    data.child('userId').val() === auth.uid
    

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 2019-09-24
      相关资源
      最近更新 更多