firebase - 与我在客户端代码中创建的内容相匹配的 firebase 规则是什么?
问题描述
我正在尝试设置对自己用户在 firebase 实时数据库中写入的数据的读取访问权限。
我在代码中以这种方式为每个firebase条目提供了我认为该条目的uid:
final DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Chat").child(myId));
但以下代码在 firebase 实时数据库中不起作用:
{
"rules": {
"Chat": {
"$uid": {
".read": "$uid === auth.uid",
(more code here)
}
}
}
}
我正在使用匿名签名登录firebase,也许这就是它无法将其识别为uid的原因,或者只是这不是uid。
这将是这种情况下的firebase规则?我想通过更改“$whatever_this_field_is_understood_by firebase_rules”的“$uid”它会起作用。
这可能吗?
PD:根据 Frank van Puffelen 的要求,我正在描述我的实时数据库结构:
Level1
Level2 (The one corresponding to "Chat")
Level3.1 (this one should match with the id, it's named with its name)
Level4 (field 1)
Level4 (field 2)
Level4 (field 3)
Level3.2
Level4 (field 1)
Level4 (field 2)
Level4 (field 3)
另一方面,我认为通过将规则更改为“.read”:“$uid === $uid”找到了解决方案,但我无法正确测试它。
我想检查是否有 $uid 的用户,例如“222”试图访问“111”的用户的字段 1,这是不可能的,但我无法找到一种方法来做到这一点代码作为测试。
有人可以确认这是正确的方式吗,或者我该如何进行上述测试?
解决方案
推荐阅读
- java - spring-boot:在没有 mvn install 的 Maven 多模块项目中运行
- mongodb - MongoDB 如何保持数据同步
- mysql - MySQL:LIKE 中没有变音符号的结果
- django - 由于静态错误,无法在 Heroku 上部署 Django
- multithreading - 为什么一个 actix_web::rt 未来在另一个处于活动状态时被丢弃,为什么另一个从未被丢弃?
- javascript - 有没有办法引用从 JavaScript 类实例化的所有对象?
- json - 过滤时遇到问题,布尔问题
- reactjs - 使用 socket.io 更改 getServerSideProps 中的 props 在终端控制台和浏览器中返回两个不同的值
- javascript - ExtJS - 如何在不继承类的情况下将新配置项传递给组件?
- javascript - 如何使用钩子在 React 中创建状态数组?