2016-02-14 84 views
0

我使用下面的安全规则:为什么没有通过Firebase验证?为什么没有返回错误信息?

{ 
    "rules": { 
     ".read": true, 
     ".write": true, 
     "chat": { 
      ".read": true, 
      ".write": true, 
      ".validate": "newData.hasChildren(['author', 'message'])" 
     } 
    } 
} 

而且我使用$add保存在这种格式对象,我chat $ firebaseArray:

{message: "hello there", author: {emailAddress: "[email protected]"}} 

但如果.validate是它总是失败定义。如果未定义.validate,则会正确保存。所以,我想延长$ firebaseArray这样的:

var myFarr = $firebaseArray.$extend({ 
     $$error: (err) { 
      console.log(err) 
     } 
    }) 

    this.messages = myFarr($scope.firebaseData.$ref().child('chat')) 

    this.sendEmail = (function(_this) { 
     return function(email) { 

     _this.messages.$loaded().then(function(data) { 
      data.$add(email); 
     })["catch"](function(err) { 
      console.error(err); 
     }); 

     }; 
    })(this); 

$$error方法似乎永远不会触发。

为什么我的有效数据无法验证?我如何得到相应的错误消息?

+0

请编辑您的问题以包含失败的'$ add()'操作。 –

+0

@FrankvanPuffelen完成! – zakdances

回答

0

它看起来像您缺少规则中的特定聊天消息的级别:

{ 
    "rules": { 
    ".read": true, 
    ".write": true, 
    "chat": { 
     "$chatid": {  
     ".read": true, 
     ".write": true, 
     ".validate": "newData.hasChildren(['author', 'message'])" 
     } 
    } 
    } 
} 

你的规则应用验证,所有聊天消息 - 相结合,同时要运用它们到每个单独的聊天消息。

+0

此信息也位于[官方文档](https://www.firebase.com/docs/security/quickstart.html)中。我多次阅读文档,但这些信息没有注册,因为我很笨。 – zakdances

相关问题