nth-child
nth-child

Reputation: 560

Firestore security rules: regex on key

Do firestore security rules support regex on the field name? So instead of the value of username...

username.matches(REGEX)

...the key username itself:

request.resource.data.keys().matches(REGEX)

// or...
 
request.resource.data.matches(REGEX)

I've tried finding this answer in the docs but no luck.

Upvotes: 1

Views: 142

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50930

request.resource.data.keys() is an array of keys and you cannot loop over list items in security rules. The best you can do is check for every key and then check if it matches the regex.

allow write: if request.resource.data.keys()[0].matches('REGEX')

You would have write same statement for all list items ([1], [2]...) and it's still difficult to guess how many keys that object has.

Upvotes: 1

Related Questions