Firebase 限制对所有者的访问

Firebase restrict access to owner

假设我正在使用 firebase 创建一个博客,有多个 authors 每个都在写自己的 posts

因此有一个 posts 集合和一个 authors 集合,其规则如下:


我有两个问题,第一,我应该使用哪种数据库模式?

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

{
  "rules": {
    ".read": true,
    ".write": true
  }
  // to complete ..
}

首先:您可以使用 ng-show、ng-hide 但这不是最佳解决方案。下面是关于 DoubleClick Campaign Manager 如何处理用户身份验证的 link。 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
      }
    }
}

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