Firebase Rules - Allow only specific users to access private chat

538 Views Asked by At

I'm creating an application that uses Private chats to let people communicate.

I have 2 trees. One contains all the messages, and the other contains details about every chat. (necessary to show it on "My chats" activity without loading the whole messages tree).

My structure is:

PrivateChatsDetails

Each privatechatdetails key contains uid1 & uid2, lastMessage node with details about the last message that has sent, and 'users' node that contains 2 users details, keys are the uids.

I want to show each user only the chats that he's in. How can I achieve that using Firebase Rules?

For now I'm using orderByChild & equalTo trick -

mFirebaseDatabaseReference.child("privateChatsDetails").orderByChild("users/" + mUid + "/chat").equalTo(true)

Working perfectly, but I want to order the list by last message timestamp, so I need to do that user chats check using Firebase Database Security Rules.

Thanks in advance.

0

There are 0 best solutions below