我正在尝试基于Firebase的社交应用,我希望通过使用Firebase规则来保护用户删除朋友。
我存储朋友的数据库表的结构如下:
Friends
{
user1
{
user2 {friend_username=user2}
user3 {friend_username=user3}
}
user2
{
user1 {friend_username=user1}
user3 {friend_username=user3}
}
}
让我们说user1从他的朋友列表中删除user2,我当前的问题是如何正确地制裁删除操作,因为它需要两个删除的粉丝:首先从user1 friendlist删除user2,从user2 friendlist删除user1 。
我尝试了以下操作,但收到错误:
"FRIENDS" :{
"$username":{
//Users can read as long as they are authenticated and their auth.name matches the table key
".read": "auth != null && auth.name === $username",
//Delete should be allowed if the auth.name matches an entry in the table 'Friends' (first part of the deletion) and if the auth.name requesting the delete is included in the 'friend_username' value inside the user2 friends (second deletion) .
".write": "auth != null && root.child('FRIENDS').hasChild(auth.name) && root.child('FRIENDS').child($username).child(auth.name).child('friend_username').val()=== auth.name"
请注意我使用粉丝更新来执行删除。
我不能用一种适当的结构化方式来包围这个删除......任何建议???
谢谢!