U
U
Username2020-11-17 14:02:02
JavaScript
Username, 2020-11-17 14:02:02

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()


those. you need to provide access to the document if you know its identifier

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Username, 2020-11-18
@dalv_happy

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 question

Ask a Question

731 491 924 answers to any question