Allow read in FireStore rules based on timestamp value in document

前端 未结 5 1165
再見小時候
再見小時候 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

    trying switching the < to >.

    request.time will be the time of accessing the document while resource.data.date should be the creation timestamp of the document.

    try using this for your security rules:

        allow read: if request.time > (resource.data.timestampPropertyName + duration.time(1, 0, 0, 0));
    

    duration.time(4, 3, 2, 1) will create a four hour, three minute, two second, one nanosecond duration.

    More information can be found at: https://firebase.google.com/docs/firestore/reference/security/#timestamp

    Do remember to wait for sometime after saving your security rules for it to take effect!

提交回复
热议问题