skip to Main Content
rules_version = '2';
firebase.storage {
  match /b/{bucket}/o {
    match /Users/{userId} {
    allow read: if request.auth != null;
    allow write : if itemDelete(userId);
    }
    function itemDelete(userId){
    return userId != '1.jpg' || '2.jpg' ;
    }
}
  }

How can I use OR || operator in firebase security rules if I use userId != ‘1.jpg’ this works but when I use userId != ‘1.jpg’ || ‘2.jpg’ this not work.

Please help me

2

Answers


  1. From the doc:

    allow rules consist of a method, such as read or write, as well
    as an (optional) condition.

    In your case it means that itemDelete(userId) should return a boolean.

    But with

    function itemDelete(userId){
       return userId != '1.jpg' || '2.jpg' ;
    }
    

    it is not the case.

    It’s not clear to me what is the exact logic of the current code of the itemDelete() function so I let you adapt it in such a way it returns a boolean in line with your security requirements.

    Login or Signup to reply.
  2. What you’re trying to do is actually an AND condition and expressed like this:

    function itemDelete(userId){
      return (userId != '1.jpg') && (userId != '2.jpg');
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search