Validation Firebase规则:允许推送但不允许更新
我正在努力理解如何允许用户在列表中创建新记录,但只允许创建者更新自己的帖子 例如,以下结构:Validation Firebase规则:允许推送但不允许更新,validation,firebase,firebase-realtime-database,firebase-security,data-security,Validation,Firebase,Firebase Realtime Database,Firebase Security,Data Security,我正在努力理解如何允许用户在列表中创建新记录,但只允许创建者更新自己的帖子 例如,以下结构: post { post1: { author: "user1" text: "Some text" } post2: { author: "user2" text: "Some text 2" } } 在这里,我希望两个用户都能够创建新的帖子。但也可以保护post2不被user1编辑。因此,只有user1可
post {
post1: {
author: "user1"
text: "Some text"
}
post2: {
author: "user2"
text: "Some text 2"
}
}
在这里,我希望两个用户都能够创建新的帖子。但也可以保护post2不被user1编辑。因此,只有user1可以编辑post1,只有user2可以编辑post2。您可能希望执行以下操作:
{"rules": {
"post": {
"$id": {
".write": "auth !== null && (!data.exists() || data.child('author').val() === auth.uid)"
}
}
}}
在这里,仅当用户已登录且a)尝试写入的节点为空或b)尝试写入的节点由当前用户编写时,才允许写入