【问题标题】:How to specify firebase database rules "out of the scope"?如何指定firebase数据库规则“超出范围”?
【发布时间】:2018-11-28 22:22:31
【问题描述】:

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

database: {
  users: {
    uniqueUserId1: {
      name: "an user",
      company: "Company1",
      rank: "manager"
    }
  }
  rota: {
    Company1: {
      2018: "rota for 2018"
    }
  }
}

所以我不想让用户阅读所有公司名单,而只是他们自己的公司名单。

对于用户规则来说并不难:

rules: {
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    },

    //But a bit complicated for things "outside the scope".
    //What I want is something like:

    "rota": {
      "$company": {
        ".read": "$company === users[auth.uid].company",
        ".write": "$company === users[auth.uid].company && users[auth.uid].rank === 'manager'"
      }
    }
  }
}

我知道这些规则不起作用,但是如何解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    您需要以root 开头来构建用户数据的路径。所以你正在寻找这样的东西:

    ".read": "$company === root.child('users').child(auth.uid).child('company').val()",
    

    另见:

    【讨论】:

    • child(auth.uid) 应该没有单引号
    • 好收获!固定。
    猜你喜欢
    • 2020-04-13
    • 2014-07-10
    • 1970-01-01
    • 2017-10-08
    • 2017-07-15
    • 2016-07-05
    • 2011-01-17
    • 2017-04-14
    • 2018-08-27
    相关资源
    最近更新 更多