我的数据库结构是
Homeland
+Ui4PSHU0kCPGpFJ6jwiJpodLvEds
+service
+quta
+period
+55dwaSHU0kCPGpFJ6jwiJpodLvEds
+service
+quta
+period
我想公开“服务”和“ quta”子项,但只有注册用户可以显示“句点”子项。但是关于我的用户目录是否存在问题。
首先,我想测试$ uid的能力。但是我不能。当我将$ uid删除时,只能使用“ Homeland”,这是可行的。
{
"rules": {
"Homeland": {
"$uid" : {
".read": true,".write": "auth !== null"
},},".read": "auth !== null",".write": "auth !== null"
}
}
这是工作
{
"rules": {
"Homeland": {
".read": true,".write": "auth !== null"
},".write": "auth !== null"
}
}
更新
按照samthecodingman所述更改我的安全规则。
{
"rules": {
"Homeland": {
"$uid" : {
"service": {
".read": true,// <-- publically readable
".write": "auth.uid === $uid" // <-- writable only by owner
},"quta": {
".read": true,"period": {
".read": "auth !== null",// <-- readable by any logged in user
".write": "auth.uid === $uid" // <-- writable only by owner
}
},"$other": { // <-- everywhere else not named above
".read": "auth !== null",// <-- allows read if logged in
".write": "auth !== null" // <-- allows write if logged in
}
}
}
代码
var kullanici = firebase.database().ref().child("Homeland").child(uservaluefrominput).child("service");
kullanici.on('value',function(datasnapshot) {
sifre = datasnapshot.val();
console.log(sifre);
});
但是代码和模拟都被拒绝读取值。
捕获错误。注意:这次我宣布清除用户ID。
try {
kullanici = firebase.database().ref().child("Homeland").child("Ui4PSHU0kCPGpFJ6jwiJpodLvEO2").child("service");
kullanici.on('value',function(datasnapshot) {
sifre = datasnapshot.val();
console.log(sifre);
});
} catch (someError) {
console.log('got some error: ',someError);
}