Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Firebase security rules "hasAny" vs "in" with javascript library is inconsistent

This is very counter intuitive but is the javascript library somehow not fully compatible with Firestore security rules?

I would assume there is no connection between security rules syntax and client side requests.

However, Im getting this behavior in a snippet of Firestore security rules:

// Works fine in tests with test suite
// Does NOT work with javascript library
request.auth.token.roles[userRole].hasAny([ "admin", "owner" ])

// Works fine in tests with test suite
// Also works fine with javascript library
request.auth.token.roles[userRole] in ([ "admin", "owner" ])

Edit: The error on the emulator is very descriptive:

function not found error: name: [hasany]

So basically it seems that the javascript library isn't compatible with the security rules?

Im using the latest version of everything:

  • Emulator (firebase-tools): 10.2.2
  • Javascript SDK: 9.6.8
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

hasAny is a construct of the Firestore security rules and does not exist in regular JavaScript arrays.

Your in solution in JavaScript is interesting, as I probably would've used some() for this.

about 4 years ago · Juan Pablo Isaza Report

0

Obviously it was my fault.

This:

request.auth.token.roles[userRole]

Returns a String. hasAny is a function of the List interface. It was passing all the tests because in the mocks the value was being mapped as an array. When calling from the client the rules logically failed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!