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?

1 answer

  • answered 2018-01-12 09:25 Michael Bleigh

    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.