2017-09-11 17 views

回答

2

如果你已经知道admin是,在你的问题user123。然后,你的数据库规则应该像

"entities": { 
    "$entryId":{ 
     // you don't what others to see other to see teh data 
    ".read": "auth.uid == 'user123'" 
     // any one who is logged in should write to the /entries node 
    ".write": "auth.uid != null" 
    } 
} 

如果你什么使规则更加动态的,那么你可以做

"entities": { 
    "$entityId":{ 
     // you don't what others to see other to see teh data 
     ".read": "root.child('users').child(auth.uid).child('isAdmin').val() == true || root.child('entities').child($entityId).child('uid').val() == auth.uid" 
     // any one who is logged in should write to the /entries node 
     ".write": "auth.uid != null" 
    } 
} 

你可以从这里https://firebase.google.com/docs/reference/security/database/

或者获取更多信息,您可以将您的输入模型更改为用户特定的

{ 
    "entities" :{ 
    "user465": { 
     "entry456": { 
     "text" : "Some sample text" 
     } 
    } 
    } 
} 

In这种情况下,你写规则

"entities": { 
    "$userId":{ 
    // you don't what others to see other to see teh data 
    ".read": "root.child('users').child(auth.uid).child('isAdmin').val() == true || $userId == auth.uid" 
    // any one who is logged in should write to the /entries node 
    ".write": "auth.uid == $userId" 
    } 
} 
+0

规则是动态的。通过此规则,输入条目的用户无法阅读。例如,'user123'应该能够读取'entry456' – npk

+0

@Nameer查看更新的答案,您也可以更改您的条目模型。 – bash

+0

但管理员无法遍历所有条目,它显示'权限被拒绝'错误。 – npk

相关问题