Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda