firebase - 只有用户可以修改在 Firebase 中有自己的数据
问题描述
我想让只有用户能够创建新帖子,并且只有用户才能修改他们创建的帖子。喜欢删除或编辑!
数据库结构
{
"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() )"
}
}
}
解决方案
您不能只使用属性访问器表示法来获取数据的子值。您必须调用该child()
函数来获取孩子,并调用该函数val()
来获取其值。
所以:
data.child('userId').val() === auth.uid
推荐阅读
- python - 从列表中查找具有特定单词的列
- javascript - 用其他文本替换部分字符串?
- c++ - 将excel文件读入struct c++
- javascript - Tensorflow.js 神经网络中的反向传播
- html - 我怎样才能使这个布局响应?
- firebase - Firebase 身份验证用户信息流
- javascript - 我的 JavaScript 代码在使用 000webhost 托管的网站中无法正常工作
- reactjs - 在 create-react-app 中导入 src 之外的 react 组件文件会出现错误 对实验语法“jsx”的支持当前未启用 (9:9)
- java - 如何解析另一个 JSONArray 中的 JSONArray
- ios - UITableViewCell 与 UIStackView 与不同的项目?