【问题标题】:Limit write access to Firebase email user限制 Firebase 电子邮件用户的写入权限
【发布时间】:2013-11-03 21:50:21
【问题描述】:

假设我为我的 Firebase 集合创建了一个新的 Email / Password 用户,名为 bob@example.com

我现在如何将对该集合中任何内容的写入权限限制为专门针对该用户?

{
  "rules": {
    ".read": true,
    ".write": false
  }
}

...?

【问题讨论】:

    标签: firebase firebase-security


    【解决方案1】:

    您可能需要更具体一些才能获得比security rules documentation 更有帮助的东西。但要回答您的问题,假设您想将整个 Firebase 写入权限限制为 Bob:

    {
      "rules": {
        ".read": true,
        ".write": "auth.email == 'bob@example.com'"
      }
    }
    

    假设您想将 Firebase 中的 item 集合限制为 Bob:

    {
      "rules": {
        ".read": true,
        "items": {
          ".write": "auth.email == 'bob@example.com'"
        }
      }
    }
    

    【讨论】:

    • 我不知道我是怎么错过的。感谢您链接文档!那么auth 对象是rules 内可访问的范围,而items 是集合对象某些部分的句柄?如果你有 items.something.items 会发生什么? --- 或者假设本例中的items是从父节点开始的。
    • 是的 auth 在规则中可用; items 只是 Firebase 根目录下的一个示例父节点(只有 Bob 可以存储 item 对象)。 "rules" 将匹配从根开始的数据结构,因此如果 Bob 的数据位于 /items/something/items,您将拥有 "rules":{"items":{"something":{"items": "auth.email == "bob@example.com"}}}。无论如何,请浏览一下文档。
    • 我有一个很好的跟进:stackoverflow.com/questions/19821571/…
    猜你喜欢
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 2013-12-24
    • 2013-02-21
    • 2013-03-07
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多