我的规则看起来像这样 -
{
"rules": {
"customer": {
"$user_id": {
".write": false,
".read" : "$user_id === auth.uid"
}
},
"franchises":
{
".read": true,
".write": "root.child('customer').hasChild(newData.child('salon_id').val())"
}
}
}
我想在特许经营中添加具有salon_id的数据,并且我想确保此salon_id作为uid存在于客户中。
我收到错误
PERMISSION_DENIED:权限被拒绝
使用代码编辑 -
var ref = firebase.database().ref('franchises');
ref.push({
address: address,
contact_no: contact_no,
contact_person_name: contact_person_name,
name: textinputPlaceName,
salon_id: salon_id
});
答案 0 :(得分:0)
您在规则中错过了一个级别:
"franchises": {
".read": true,
".write": "root.child('customer').hasChild(newData.child('salon_id').val())"
}
当您写信至franchises
时,这适用。但是,由于您的代码调用了ref.push()
,因此您可以更深入地编写一个级别。所以规则应该是:
"franchises": {
".read": true,
"$franchiseId": {
".write": "root.child('customer').hasChild(newData.child('salon_id').val())"
}
}