【问题标题】:auth.uid not working in firebase rulesauth.uid 在 firebase 规则中不起作用
【发布时间】:2017-05-01 14:34:52
【问题描述】:

我正在尝试向我的 Firebase 应用程序添加安全规则。但是auth.uid 不起作用..

这是我的两条安全规则..

  "groups": {
      "$groupid":{
          ".read" : true,
          ".write" : "root.child('groupmembers').child($groupid).child('admins').child(root.child('users').child(auth.uid).child('username').val()).val()==true"
      }

    },
    "groupchat":{
      "$chatid":{

          ".read" : "root.child('groupmembers').child($chatid).child('members').child(root.child('users').child(auth.uid).child('username').val()).val()==true",
          ".write" : "root.child('groupmembers').child($chatid).child('members').child(root.child('users').child(auth.uid).child('username').val()).val()==true"

    }

  }

在第一条规则上 auth.uid 正在工作。但在第二条和其他规则的情况下,auth.uid 根本不起作用。我添加了我的原始 uid 代替 auth.uid 并且所有规则都正常工作。

客户端操作示例..

 Map<String, Object> map = new HashMap<String, Object>();
 map.put("username", userid);
 map.put("message", userid + " Created This Group.");
 map.put("timestamp", ServerValue.TIMESTAMP);
 map.put("zcode",chat_key);
 map.put("type", "action");
 FirebaseDatabase.getInstance().getReference()
    .child('groupchat')
    .child(groupid)
    .push()
    .updateChildren(map);

用户结构

"users":{
  "my_uid" : {
    "email" : "example@gmail.com",
    "username" : "user1"
  }
}

组成员结构

"groupmembers":{
  "groupid":{
    {
      "admins" : {
        "user1" : true,
        "user3" : true
      },
      "members" : {
        "user1" : true,
        "user2" : true,
        "user3" : true,
        "user4" : true
      }
    }
}
}

那么我该如何解决这个问题呢?

【问题讨论】:

  • 请分享minimal code that reproduces the problem。除了失败的代码之外,还包括数据库中现有的相关 JSON(作为文本,没有屏幕截图)。您可以通过单击 Firebase Database console 中的“导出 JSON”链接来获取此信息。
  • 添加了代码。但这不是只有这条规则的问题。除了第一条规则,在每条规则中 auth.uid 的行为都是一样的……@FrankvanPuffelen
  • 我不会立即看到规则有什么问题,除非 groupid 不匹配。但除此之外,也许其他人发现了错误。

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


【解决方案1】:

我认为这是因为版本不匹配或使用的包不同,所以它不能 auth.uid

【讨论】:

    猜你喜欢
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2018-03-12
    相关资源
    最近更新 更多