Search code examples
google-cloud-firestorefirebase-security

Array.contains in Firestore rules


How to use the JS native array.contains in Firestore rules?

function isCool() {
  return [
    'xxx',
    'yyy',
  ].contains(req.auth.uid)
}

The function above gives an error


Solution

  • You are looking for in operator:

    function isCool() {
      return request.auth.uid in ['xxx', 'yyy'];
    }
    

    It returns true if the value is present in the given list/array.