firebase javascript访问被拒绝angularjs可能是不好的规则?

时间:2016-02-07 01:35:34

标签: javascript firebase firebase-security firebase-realtime-database

我试图检查用户是否可以注册我的应用程序(在这部分我只是检查他的用户名,但顺便说一句,我想确保它无法注册即使用户绕过此检查过程,也会使用此用户名。所以这是我的火力规则:

    {
  "rules": {
    "userPublic": {
      "$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",
        // grants read access to any user who is logged in with Facebook
        ".read": true,
        "username": {
           ".validate": "!root.child('usernameLookup/'+newData.child('username').val()).exists()"
        }
      }
    },
    "userPrivate": {
      "$uid": {
        "username": {
           ".validate": "!root.child('usernameLookup/'+newData.child('username').val()).exists()"
        },
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",
        // grants read access to any user who is logged in with Facebook
        ".read": "auth !== null && auth.uid === $uid"
      }
    },
    "usernameLookup": {
    "$username": {
       // not readable, cannot get a list of usernames!
       // can only write if this username is not already in the db
       ".write": "!data.exists() && !root.child('userPublic/'+auth.uid).exists()"

       // can only write my own uid into this index
       //".validate": "newData.val() === auth.uid"
    }
    }
  }
}

如果用户存在,请检查我的源代码:

var fb = new Firebase(firebaseURL);
 fb.child('usernameLookup/'+username).set(uid(fb.getAuth().uid), function(err) {
  if( err ) {
      $scope.msg = err+"Username already exists!";
  }
  else
      {
          $scope.msg = "Success";
      }});

但我收到拒绝访问错误...请帮帮我! :(

0 个答案:

没有答案