Allow read in FireStore rules based on timestamp value in document

前端 未结 5 1155
再見小時候
再見小時候 2020-12-11 07:11

I want to create a FireStore rule that grantes read privilages to documents after the current date has surpassed a timestamp value in the document.

This is for a bl

5条回答
  •  悲&欢浪女
    2020-12-11 07:57

    NOTE: As this is my first answer on Stack Overflow, I wasn't allowed to comment on Frank van Pueffelen's answer, so just as a heads-up, the credits for this solution are his!

    The request has a request.time which is a timestamp, and Firestore allows for basic math operators on timestamp <> timestamp operations, so your request.time < resource.data.date will work ;)

    service cloud.firestore {
      match /databases/{database}/documents {
        match /Articles/{article}{
       allow read: if request.time < resource.data.date
        }
      }
    }
    

    This is based on my personal testing on 2018.09.29

提交回复
热议问题