Search code examples
javascriptfirebasefirebase-storagefirebase-security

How to add OR operator in Firebase Security Rules


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


Solution

  • 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');
    }