2015-09-26 82 views
1

所以我有这个数据库的结构:Firebase安全规则,设置孩子不可读?

enter image description here

在型材我要寄&提供商名称只为管理员和 用户名可读为每个登录的用户可读。 我如何实现这一目标?

这里是我的规则:

{ 
    "rules": 
    { 
    "users": 
    { 
     "$uid": 
     { 
     // grants write access to the owner of this user account whose uid  must exactly match the key ($uid) 
     ".write": "auth !== null && auth.uid === $uid", 
     "profile": 
     { 
      // grants read access only for registered users 
      ".read": "auth !== null", 
      "email": 
      { 
      // This doesn't work with firebase as I was reading doc.      
      ".read": false 
      } 
     } 
     } 
    } 
    } 
} 
+1

当您有权读取该节点中的所有数据时,Firebase将只返回一个节点。因此,您必须对数据建模,以便将公共数据和私有数据存储在不同的顶级节点中。 (https://www.firebase.com/docs/security/guide/securing-data.html#section-filter) –

+0

请给我看一个简单的例子吗? – Dragod83

回答

1

那么一点研究后和阅读去正规化结构我想这样会工作。事实是,我很想嵌套,但在firebase上可能是一个坏主意。

{ 
     "rules": 
     { 
     "users": 
     { 
      "$uid": 
      { 
      // grants write access to the owner of this user account whose uid must exactly match the key ($uid) 
      ".write": "auth !== null && auth.uid == $uid", 
      "public-profile": 
      { 
       // grants read access only for registered users 
       ".read": "auth !== null" 
      } 
      } 
     }, 
     "private-profile": 
     { 
      "$uid": 
      { 
       ".read": "root.child('users').child(auth.uid).child('role').child('admin').val() === 'true' && root.child('users').child('1').child('role').child('admin').val() === 'true'", 
       ".write": "root.child('users').child(auth.uid).child('role').child('admin').val() === 'true' && root.child('users').child('1').child('role').child('admin').val() === 'true'" 
      } 
     } 
     } 
    } 
相关问题