Debugging Security Rules for Cloud Firestore

I set security rules for my database Google Cloud Firestore. I try to allow deletion of a document only if its time value exceeds 30 days in the past using the following logic:

allow delete: if
   resource.data.locked == false
   && (request.time - resource.data.timeStamp).seconds > 2592000;

When I try to do this, I get Error: Missing or insufficient permissions. So the first question is - am I going to do it wrong or is my logic corrupted?

And as the next question, is there a way to debug the rules? Perhaps the equivalent console.log, thanks to which I can see the result of conditional rules as they are applied and verify that I am not sending a string instead of a timestamp or something so stupid?

I assume that request.timethere is “now” and that my is resource.data.timeStampcorrect, and one minus the other returns a Durationand that thatDuration.secondsreturns number, but I am newb, and any of these assumptions may be wrong, and it would be great to see these values ​​as they are processed.

Greets everyone

+4
source share
1 answer

I did not check, try something like this

request.time < resource.data.timeStamp + duration.value(30, "d");

And your second question, I do not know. There is no simulator in the Realtime database. Remember that it is still in beta.

0
source

Source: https://habr.com/ru/post/1688086/


All Articles