2015-04-19 42 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