rijin
rijin

Reputation: 1759

Firebase Rules for Cloud Firestore to limit maximum number of documents

I have following use case.. I don't want to allow user control document limit in cloud firestore, I want to have firebase rule restrict it.

For eg. I have a products collection, user can do pagination (max=10) per page. if its browser side, user can easily change and get all the products list. Is there any settings or rules to control this?

Upvotes: 5

Views: 2337

Answers (1)

Michael Bleigh
Michael Bleigh

Reputation: 26313

You can protect this using the query property of the request object (see docs). Basically you can write a rule with a condition on the limit:

allow read: if request.query.limit != 10

The above rule will prevent the query from going through if the limit is not set to 10.

Upvotes: 8

Related Questions