Firebase使用newData进行验证 [英] Firebase validate with newData
问题描述
我正在通过一个很好的例子来说明如何构建数据,如Kato在本文中所示: 我没有任何运气验证工作正常。 数据结构是: 以下是一个屏幕截图: 如果我尝试写下面的内容: 使用此规则在accepted_invites中输入: ():root.child('invites /'+ $ game_id +'/'+ newData.val())。exists() 我尝试使用模拟器,但我得到 完成我有他们的规则︰ 如果您有兴趣在路径中使用这些数据的某些部分,我建议在其中添加另一个验证规则更深的路径,例如: I'm working thru the excellent example on how to structure data as shown by Kato in this post:
Firebase user account security with firebaseSimpleLogin I'm not having any luck getting validate to work properly. The data structure is : here's a screen shot:
Firebase data If I try and write the following it will make an entry in accepted_invites with this rule : but not I tried using the simulator but I'm getting
Type Error: + only operates on numbers and strings. Here's the complete rules as I have them:
The If you're interested in using some portion of that data within the path, I would recommend just including another validation rule at a deeper path, such as:
这篇关于Firebase使用newData进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
accepted_invites
game1
descfun game
invites
game1
uuidAAA true
uuidBBB true
Firebase数据
ref 。.child( accepted_invites)子( 的Game1)子( userTwo)子( uuidBBB)的setValue(真)。
。validate:root.child('invites /'+ $ game_id +'/ uuidBBB')。exists()
$ c $
$ b
类型错误:+只对数字和字符串进行操作。
{
rules:{
.write:true ,
.read:true,
accepted_invites:{
$ game_id:{
$ user_id:{
//这个验证规则失败
//\".validate:root.child('invites /'+ $ game_id +'/'+ newData.val())exists()
//这个工程
.validate:root.child('invites /'+ $ game_id +'/ uuidBBB')。exists()
}
}
}
}
}
newData
关键字是一个涉及所有传入数据的特殊属性,但是它在路径表达式中是不允许的,因为它可能不是是一个字符串。也就是说,它可能是一个对象。
$ p $ {
rules:{
.write:
.read:true,
accepted_invites:{
$ game_id:{
$ accepting_user_id:{
$ sending_user_id :{
.validate:root.child('invites')。child($ game_id).child($ sending_user_id).exists()
}
}
}
}
}
}
accepted_invites
game1
desc "fun game"
invites
game1
uuidAAA true
uuidBBB true
ref.child("accepted_invites").child("game1").child("userTwo").child("uuidBBB").setValue(true);
".validate": "root.child('invites/'+$game_id+'/uuidBBB').exists()"
".validate": "root.child('invites/'+$game_id+'/'+newData.val()).exists()"
{
"rules": {
".write" : true,
".read" : true,
"accepted_invites": {
"$game_id": {
"$user_id": {
//This validate rule fails
//".validate": "root.child('invites/'+$game_id+'/'+newData.val()).exists()"
//This one works
".validate": "root.child('invites/'+$game_id+'/uuidBBB').exists()"
}
}
}
}
}
newData
keyword is a special attribute referring to all incoming data, but it is not permitted in path expressions because it may not be a string. i.e., it could very well be an object.{
"rules": {
".write" : true,
".read" : true,
"accepted_invites": {
"$game_id": {
"$accepting_user_id": {
"$sending_user_id": {
".validate": "root.child('invites').child($game_id).child($sending_user_id).exists()"
}
}
}
}
}
}