从其他路径引用以进行子名称验证
Reference from other path for child name validation
我有这样一个数据库:
"users": {
"gh483cwonaz8o3mff3": {
"nick": "mutlu",
"birthyear": "1996"
}
}
"nicks" : {
"mutlu": {
"uid": "gh483cwonaz8o3mff3"
}
}
写入数据库的第一个数据是"users"。比到"nicks"。但是 "nicks" 中的 "mutlu" 应该与 "users>gh483cwonaz8o3mff3>nick" 值相同。
如何确定将写入 "nicks" 的数据的安全规则。
我尝试了这个但没有成功:
"nicks": {
".write": "auth.token.email_verified == true && newData.hasChild(root.child('users').child(auth.uid).child('username').val())"
}
您在规则中构建的路径与您共享的 JSON 中的结构不匹配。
我认为您写入昵称的安全规则应该是:
{
"rules": {
"nicks": {
"$nick": {
".write": "auth.token.email_verified == true &&
root.child('users').child(auth.uid).child('nick').val()) == $nick"
将您的 JSON/path 放在规则旁边最容易发现此类错误:"users": { "gh483cwonaz8o3mff3": { "nick": "mutlu",
我有这样一个数据库:
"users": {
"gh483cwonaz8o3mff3": {
"nick": "mutlu",
"birthyear": "1996"
}
}
"nicks" : {
"mutlu": {
"uid": "gh483cwonaz8o3mff3"
}
}
写入数据库的第一个数据是"users"。比到"nicks"。但是 "nicks" 中的 "mutlu" 应该与 "users>gh483cwonaz8o3mff3>nick" 值相同。 如何确定将写入 "nicks" 的数据的安全规则。 我尝试了这个但没有成功:
"nicks": {
".write": "auth.token.email_verified == true && newData.hasChild(root.child('users').child(auth.uid).child('username').val())"
}
您在规则中构建的路径与您共享的 JSON 中的结构不匹配。 我认为您写入昵称的安全规则应该是:
{
"rules": {
"nicks": {
"$nick": {
".write": "auth.token.email_verified == true &&
root.child('users').child(auth.uid).child('nick').val()) == $nick"
将您的 JSON/path 放在规则旁边最容易发现此类错误:"users": { "gh483cwonaz8o3mff3": { "nick": "mutlu",