Firebase Database Rules to match row

二次信任 提交于 2019-12-04 10:26:16

Firebase rules are atomic. So if you try to read /chat (and thats what you are currently doing) it will only check the /chat branch rules. Since you dont have any rule in /chat it goes for the default thats is not giving access. Therefore, your rules would only be evaluated in case you were trying to read /chat/chatId.

One possible solution you could go for is to store a list of chats which each user is part of. So you can keep your current chat branch but store another branch in the database with the following structure:

user_chats: {
    uid1: {
        chatId1: true,
        chatId2: false
    }
    uid2: ...
}

And rules:

"user_chats": {
   "$uid": {
       ".read": "auth.uid === $uid",
       ".write": "auth.uid === $uid"
   }
}

Then you could keep your chat rules like you already have them but first get the data from /user_chats/uid and then for each chatId retrieved you you will need to read on chat/chatId.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!