Answer the question
In order to leave comments, you need to log in
How to allow access to a document in Firestore, knowing its id?
Good day!
It is necessary to implement a chat on the firestore between two anonymous users. There is a collection chats, with a list of documents, you need to deny access to getting a list of all documents in the collection, and allow access to the document if the user knows its identifier.
Example:
Such a request should cause an error for the user (permission denied) Such a request should return all fields of the document
firebase.firestore().collection("chats").get()
firebase.firestore().collection("chats").doc("fK3ddutEpD2qQqRMXNW5").get()
Answer the question
In order to leave comments, you need to log in
Found the answer:
You can split the reading rules and the list. Get rules apply to single document requests, and list rules apply to requests and collection ( docs ) requests.
match /users/{userId} {
//signed in users can get individual documents
allow get: if request.auth.uid != null;
//no one can query the collection
allow list: if false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question