【问题标题】:Firebase rules to give read permission based on other related data not workingFirebase 规则根据其他相关数据授予读取权限不起作用
【发布时间】:2017-02-08 21:06:37
【问题描述】:

所以我正在使用 Firebase 制作日历应用程序,但遇到了一些问题。

我的数据库结构是这样的:

- calendar
  - $year
    - $month
      - $day
        - $uid
          - name
          - arrivalStatus
- users
  - $uid
    - name
    - team

所以我想做的是,同一团队中的人必须能够阅读彼此在日历中的条目。我已经设置了这样的规则:

{
 "rules": {
   "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
      }
   },
   "calendar": {
    "$year":{
     "$month":{
       "$day":{
        "$uid":{
          ".read": "auth != null && 
                    root.child('users/'+auth.uid+'/team').exists() && 
                    root.child('users/'+$uid+'/team').val() == root.child('users/'+auth.uid+'/team').val()",
          ".write": "auth != null && auth.uid == $uid"
          }
        }
      }
    }
  }
 }
}

但无论出于何种原因,在通过模拟运行时,无论您在哪个团队,请求都会被批准。我错过了什么明显的东西吗?

编辑:

所以基本上让我们假设这个数据集:

-firecalender
 -calendar
  -2016
   -9
    -30
     -gsdfgd
      -Name: "MG"
      -Status:"PM"
-users
  -abcd
    -name: "Tester"
    -team: "bc"
  -efg
    -name: "noteam"
    -team: "funny inc"
  -gsdfgd
    -name: "bossman"
    -team : "bc"

在这种情况下,abcd 应该能够读取日历中每个 gsdfgd 的信息,但应该拒绝 efg 访问。

【问题讨论】:

  • 您是否尝试过在安全规则中更改 $uid 的名称。现在你在两个地方使用 $uid,也许 firebase 看不出区别。
  • 您能否展示您希望失败的操作(包含确切的路径、数据和活动 uid)以及它成功的基础数据?
  • 如果 UID 为 abcd 或 gsdfgd,则应允许基本 calendar/2016/9/30/gsdfgd/,但如果 UID 为 efg,则应拒绝

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


【解决方案1】:

我认为您的问题是您使用的是== 而不是===

示例链接:https://firebase.google.com/docs/database/security/user-security

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 2021-07-06
    • 1970-01-01
    • 2020-04-11
    • 2020-08-15
    • 2020-09-12
    • 2013-09-14
    相关资源
    最近更新 更多