【问题标题】:Custom Firebase Security Rule自定义 Firebase 安全规则
【发布时间】:2015-12-18 14:08:07
【问题描述】:

需要做什么?

  • 每个人都可以阅读项目。
  • 登录的每个人都可以将项目写入数据库。
  • 每个人都可以使用自己的 uid 作为作者来编辑项目。
  • 通过密码(不是 twitter...)登录的用户是版主,可以编辑所有项目。

数据库:

{ 
    items: [ 
        {
            title: "some title",
            content: "voila, some content",
            author: {
               uid: "FSDF-SDFSDF-SDFS-SFZE"
            }
        }, {
            title: "some second title title",
            content: "voila, some other content",
            author: {
               uid: "1234-234235-2342-2342"
            }
        }
    ]
}

规则:

"items": {
  ".read": true,
  ".write": "auth !== null",

    "$item": {
        ".read": true,
        ".write": "auth !== null && auth.provider === 'password' or root.child('items/' + $item +  '/author/uid').val() === auth.uid"
    }
}

怎么了?

【问题讨论】:

  • 对不起..还没有完全...还没有时间完成这个。当我有时间完成那个项目时会要求更多。希望很快。

标签: json firebase firebase-security


【解决方案1】:

您可以使用newData 服务器变量来获取author.uid 属性。然后用它来对照auth.uid

"items": {
  ".read": true,
  "$item": {
    ".write": "newData.child('author/uid').val() === auth.uid || auth.provider === 'password'"
  }
}

您的表达式中还有 or 这个词,而不是 ||

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 2022-12-06
    • 2016-06-27
    • 1970-01-01
    • 2018-07-23
    • 2016-08-19
    相关资源
    最近更新 更多