firebase - 通过经过身份验证的用户访问条件嵌套数据

标签 firebase

我正在尝试使新的帖子对象只能由每个帖子中存储的“成员”字典中存在的用户读取。我不断收到“7:17:无效 == 表达式:左操作数不是数字、 bool 值、字符串或 null。”关于 .read 规则:

{
  "rules": {

  "posts" : {
      ".write":true,
      "$post" : {
         ".read": "data.child('members').child(auth.uid) == true"
      }
    }  
  }
}

我在生成的 token 中传递了“uid”参数:https://www.firebase.com/docs/security/custom-login.html

目的是只允许其成员数组中存在的用户读取帖子。我在 firebase 文档、Google 群组或 Google 搜索中找不到任何有关访问嵌套数据的示例:-(

这是允许/可能的吗?

最佳答案

您需要在 .child() 之后添加 .val() 才能获取值。 :-) 尝试一下:

".read": "data.child('members').child(auth.uid).val() == true"

关于firebase - 通过经过身份验证的用户访问条件嵌套数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15059030/

相关文章:

google-app-engine - 是否可以使用 Firebase Auth 来保护我的 Google Cloud Endpoints API?

javascript - 为什么即使我有条件地渲染组件, Prop 也未定义?

android - 当应用程序处于后台状态时,Google FCM getIntent 不返回预期数据

javascript - Firebase 数据库规则。无法写入数据

android - 离线匿名使用 Firebase 进行身份验证

android - 未调用 Firebase Cloud Messaging onMessageSent

java - firebase StorageException 被打印,即使我处理它

javascript - 将 firestore DB 设置为窗口对象有多安全?

javascript - 带子集合的 Firebase 查询

android - 有没有人让 Firebase 应用索引工作?