Firebase限制对所有者的访问权限

时间:2015-04-19 14:32:59

标签: javascript firebase

我要说我使用firebase创建了一个博客,每个authors都有多个posts编写自己的posts

因此,authors集合和authors集合具有以下规则:

  • 如果经过身份验证,作者可以创建帖子
  • 如果经过身份验证,作者可以阅读其他帖子
  • 作者只能编辑自己的帖子

我有两个问题,首先,我应该使用哪种数据库架构?

  • 一个posts集合和一个单独的authors集合
  • 为每位作者嵌入posts{ "rules": { ".read": true, ".write": true } // to complete .. } 个集合

其次,我应该使用哪种安全规则?

{{1}}

1 个答案:

答案 0 :(得分:3)

首先:您可以使用ng-show,ng-hide,但这不是最佳解决方案。以下是DoubleClick Campaign Manager如何处理用户身份验证的链接。 https://docs.google.com/file/d/0B4F6Csor-S1cNThqekp4NUZCSmc/edit

第二:你可以用这种方式编写你的规则 - 在下面,根据需要改变数值。

{
    "rules": {
      "products": {
        ".read": true,
        ".write": true
      },
       "sectest": {
        ".read": true,
        ".write": "(newData.child('admin').child(auth.uid).exists()) || 
            (data.exists() && data.child('admin').child(auth.uid).val() == auth.uid) ||
            (root.child('users/'+auth.uid+'/isadmin').exists())" 
      },
      "users": {
        ".write": true,
        "$uid": {
          ".read": "auth != null && auth.uid == $uid"
        }
      },
      "venders": {
        ".read": true,
        ".write": true
      },
      "channels": {
        ".read": true,
        ".write": true
      }
    }
}

查看此角博客示例:https://github.com/yearofmoo/hexo-angular-blog-example