与我在客户端代码中创建的内容相匹配的firebase规则是什么?

时间:2019-04-04 11:51:05

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

我正在尝试设置对自己用户在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。

在这种情况下,哪个火力规则是?我想通过将“ $ whatever_this_field_is_understood_by firebase_rules”的“ $ uid”更改为有效。

这可能吗?

PD:应Frank Frank 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,那将是不可能的,但是我无法找到一种方法来以此作为测试代码。

有人可以确认这是正确的方法还是我如何进行上述测试?

0 个答案:

没有答案