I have data stored in my firebase:
firebaseRoot
admins
simplelogin:1:
users
simplelogin:1
email: abc@xyz.com
picture: csd
provider: password
uid: simplelogin:1
simplelogin:2
email: abc1@xyz.com
picture: zsd
provider: password
uid: simplelogin:1
and the following safety rules:
{
"rules": {
"admins": {
".read": "root.child('admins').child(auth.uid).val() === true",
".write": "root.child('admins').child(auth.uid).val() === true"
},
"users": {
"$user":{
".read": "$user === auth.id || root.child('admins').child(auth.uid).val() === true",
".write": "$user === auth.id"
}
}
}
}
My authorization requirements are listed below.
- Administrators
- can only be read and added by an existing administrator. It works.
- All users can be read by the administrator, but cannot write user data.
- The user can read and update their own user data.
Currently, with the above rules, I cannot read user data for both administrators and registered users. I get below error message. Please provide your help. Thank.
var rootRef = new Firebase('https://xxxxx.firebaseio.com/');
var users = rootRef.child('users');
users.on('value', function(snap) {
console.log(snap.key(), snap.val());
}, function(error) {
console.log(error);
});
Error:
Error: permission_denied: the client does not have permission to access the required data.