为什么我在 firebase 中被拒绝许可?
Why am i getting permission denied in firebase?
我正在使用 angularfire 并在实时数据库中进行批量更新
我没有写指定对象的完整路径,而是写了父对象,我传递的数据包含路径的其余部分
例如,假设我有一条像 root/$date/$uid/myObject
这样的路径
我在规则中指定
{
"rules": {
"root" : {
"$date" : {
"$uid": {
".read": true,
".write" : "auth.uid === $uid && $date.matches(/someregex/)"
}
}
}
}
在 angularfire 中,我执行以下操作
const data = {
"12-03-2020": {
"my-user-id": {
data: "hello world!"
}
}
"12-04-1236": {
"my-user-id": {
data: "hello world!"
}
},
"12-06-1960": {
"my-user-id": null
},
}
this.db.object('root').update(data).then(...)
在规则测试器中写入完整路径时,一切正常,但在我的应用程序上尝试时,我得到 Permission Denied
当设置写入 true
时,该方法也有效
更新语句的执行本质上是更新对象中每个 top-level 键的集合语句列表。这意味着您的代码正在尝试写入 root/12-03-2020
、root/12-04-1236
和 root/12-06-1960
,但在那里没有写入权限。
可以对特定属性执行深度更新,但您必须在密钥中指定属性的路径。因此,您问题中的 JSON 将折叠到此结构中以执行(仅)那些特定值的深度更新:
const data = {
"12-03-2020/my-user-id/data": "hello world!",
"12-04-1236/my-user-id/data": "hello world!"
"12-06-1960/my-user-id": null
}
...
我正在使用 angularfire 并在实时数据库中进行批量更新
我没有写指定对象的完整路径,而是写了父对象,我传递的数据包含路径的其余部分
例如,假设我有一条像 root/$date/$uid/myObject
我在规则中指定
{
"rules": {
"root" : {
"$date" : {
"$uid": {
".read": true,
".write" : "auth.uid === $uid && $date.matches(/someregex/)"
}
}
}
}
在 angularfire 中,我执行以下操作
const data = {
"12-03-2020": {
"my-user-id": {
data: "hello world!"
}
}
"12-04-1236": {
"my-user-id": {
data: "hello world!"
}
},
"12-06-1960": {
"my-user-id": null
},
}
this.db.object('root').update(data).then(...)
在规则测试器中写入完整路径时,一切正常,但在我的应用程序上尝试时,我得到 Permission Denied
当设置写入 true
更新语句的执行本质上是更新对象中每个 top-level 键的集合语句列表。这意味着您的代码正在尝试写入 root/12-03-2020
、root/12-04-1236
和 root/12-06-1960
,但在那里没有写入权限。
可以对特定属性执行深度更新,但您必须在密钥中指定属性的路径。因此,您问题中的 JSON 将折叠到此结构中以执行(仅)那些特定值的深度更新:
const data = {
"12-03-2020/my-user-id/data": "hello world!",
"12-04-1236/my-user-id/data": "hello world!"
"12-06-1960/my-user-id": null
}
...