【发布时间】:2019-12-04 15:07:38
【问题描述】:
为我的报价表添加规则后,我没有从 firebase 实时数据库中获得任何回报。我希望在 auth.uid 与报价的所有者值匹配的情况下返回所有报价。但是我什么也没得到。
谁能帮帮我?
规则指定为:
{
"rules": {
"users":{
".read": "auth.uid != null",
".write": "auth.uid != null"
},
"quotes":{
"$uid":{
".read": "data.child('owner').val() === auth.uid",
}
}
}
}
报价表的结构如下:
{
"1ec658d2-a7cb-45b8-8d9b-9c2a6783365d" : {
"dateCreated" : "2019-12-02T16:06:50+01:00",
"owner" : "DVRVSpeOXQV6wAmHAdpAe6iPQ5i2",
"ownerName" : "testOost",
"projectName" : "testProject1"
},
"96549b51-6356-4c37-a388-592561394d1a" : {
"dateCreated" : "2019-09-25T14:58:13+02:00",
"owner" : "xZBFCq4ho3V2G8dZTvK7RjsnTr43",
"ownerName" : "timcastelijn",
"projectName" : "testProject2"
}
}
我访问数据的代码是
this.props.firebase.db.ref('quotes/').on('value', snapshot => {
const quotesObject = snapshot.val();
/* quotesObject is handled here */
});
更新:已解决
@frank-van-puffelen 的解决方案解决了这个问题。
新规则:
{
"rules": {
"users":{
".read": "auth.uid != null",
".write": "auth.uid != null"
},
"quotes":{
".read": "auth.uid != null &&
query.orderByChild == 'owner' &&
query.equalTo == auth.uid" // restrict basket access to owner of quote
}
}
}
}
新的sn-p:
this.props.firebase.db.ref('quotes/').orderByChild("owner")
.equalTo(this.authUser.uid)
.on("value", snapshot => {
const quotesObject = snapshot.val();
....
});
}
【问题讨论】:
标签: javascript firebase firebase-realtime-database