2015-04-19 44 views
1

假設我正在使用Firebase創建博客,有多個authors各自編寫自己的postsFirebase限制訪問所有者

因此,有一個posts收集和authors收集與下列規則:

  • 如果驗證的作者可以創建一個帖子
  • 作者可以讀取如果驗證對方後
  • 作者可以僅編輯自己的帖子

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

  • 一個authors集合和一個獨立的posts收集
  • 一個authors收集與posts嵌入每個作者

二,我應該使用哪些安全規則?

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

回答

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

+0

https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html –

+0

很好的例子規則麥克!我一直以Firebase聊天規則爲例,但這些規則非常複雜。你的樣品更好。如果有人想驗證Mike的示例更具可讀性,則這些是Firebase的Firechat示例的規則:https://github.com/firebase/firefox/blob/master/rules.json –

+1

此集合比較簡單,比Firechat更好 - 這是一個非常複雜的應用程序(不作爲示例):https://www.firebase.com/docs/security/guide/user-security.html#section-revisiting-advanced-例。同意Mikes也相當好! – Kato