簡體   English   中英

Firebase限制對所有者的訪問權限

[英]Firebase restrict access to owner

假設我正在使用firebase創建一個博客,每個posts都有多個authors

因此,有一個posts集合和一個具有以下規則的authors集合:

  • 如果經過身份驗證,作者可以創建帖子
  • 如果經過身份驗證,作者可以閱讀彼此的帖子
  • 作者只能編輯自己的帖子

我有兩個問題,首先,我應該使用哪個數據庫模式?

  • 一個authors集合和一個單獨的posts集合
  • 一個authors集合,每個作者都嵌入了posts

其次,我應該使用哪種安全規則?

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

第一:你可以使用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
      }
    }
}

看看這個angular-blog示例: https//github.com/yearofmoo/hexo-angular-blog-example

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM