Home > Software design >  In Firestore security rules, can a custom function be used inside another custom function?
In Firestore security rules, can a custom function be used inside another custom function?

Time:05-08

In Firestore security rules, I'm writing a custom function (isEitherNotSecretOrIsOwner()), with another custom function (belongsToRequestor()) inside of it, but the official Google Firebase documentation on custom functions seems to be silent on whether this is okay or not.

Code excerpt below:

function belongsToRequestor() {
return request.auth.uid == resource.data.userId
}

function isEitherNotSecretOrIsOwner() {
resource.data.reviewPrivacy != 'keepSecret' ||
belongsToRequestor()
}

I hope this is okay, because I need to put the isEitherNotSecretOrIsOwner() inside a longer set of && conditions and I'm not sure how else to have the "either X || Y" inside a string of && conditions…

Thanks for any help!

CodePudding user response:

Calling one custom functions from within another one is indeed supported in Firestore security rules, as long as the function you're calling is in scope at the call site.

  • Related