firebase - 指定 Firebase 实时数据库中属性的可读性
问题描述
这是我的数据库的结构:
users
id1
role: 'admin',
tokens: [...]
...
这是我的规则列表:
{
"rules": {
"users": {
".read": "root.child('users').child(auth.uid).child('role').val() === 'admin'",
"$user_id": {
"role": {
".write": "$user_id === auth.uid",
".read": "$user_id === auth.uid",
".validate": "newData.child('role').val() === 'user'"
},
"tokens": {
".write": "$user_id === auth.uid",
".read": "$user_id === auth.uid"
},
"$other": {
".read": false,
".write": false
}
}
}
}
}
我的意图是允许用户(在创建帐户时)将自己的角色设置为“用户”,而不是“管理员”。用户可以自由地读取或写入自己的令牌,并且不应将其他属性写入表中。
问题是user
在创建帐户时将用户角色设置为不再起作用。我在这里想念什么?
编辑:事后看来,我想我的问题可以简化为以下内容:
在文档中,我们给出了以下示例:
{
"messages": {
"message0": {
"content": "Hello",
"timestamp": 1405704370369
},
...
}
}
{
"rules": {
"messages": {
"$message": {
".read": "true",
".write": "false"
}
}
}
}
content
有没有办法为 and等属性自定义读写行为timestamp
,或者我们可以只使用一个规则来描述整个$message
?
解决方案
推荐阅读
- apache-spark - Pyspark 作业队列配置优先级 - spark-submit vs SparkSession.builder
- javascript - 通过 api 端点访问特定项目
- javascript - React Jsx - 如何为随机报价生成器挂钩 RxJs 点击事件?
- python - 相同数据集和超参数的差异 betweek Keras 和 Tensorflow
- reactjs - 反应内存泄漏,componentDidUnmount 不起作用
- c# - 插入数据时在 xamarin 表单中出现错误:System.ArgumentNullException:'值不能为空。参数名称:取消'
- ffmpeg - 您如何将特定 X 和 Y 位置的视频与 FFMPEG 结合起来?
- java - 如何将 JSON 添加到项目的类路径中?使用 VS 代码
- ruby-on-rails - /profile 之类的路径是否生成正确的 URI?他们违反了 REST 吗?有什么影响?
- python - 用于 Awk 的 Python 子进程