Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

firebase security permission not working

I have below 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 following security 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 as below.

  1. admins can be read and added only by the existing admin only. This works.
  2. All users can be read by the admin but should not be able to write user data.
  3. a user can read and update his own user data.

Currently with above rules, I am not able read users data both for admins and logged in users. I get below error message. Please provide your help. Thanks.

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: Client doesn't have permission to access the desired data.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...