Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda