[英]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' ||
firebase 安全规则中的运算符如果我使用 userId.= '1.jpg' 这有效但是当我使用 userId.= '1.jpg' || '2.jpg' this not work.
'2.jpg' 这不起作用。
Please help me请帮我
allow
rules consist of a method, such asread
orwrite
, as well as an (optional) condition.allow
规则由一个方法组成,例如read
或write
,以及一个(可选)条件。
In your case it means that itemDelete(userId)
should return a boolean
.在您的情况下,这意味着
itemDelete(userId)
应该返回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.我不清楚
itemDelete()
function 当前代码的确切逻辑是什么,所以我让您对其进行调整,使其返回符合您的安全要求的boolean
。
What you're trying to do is actually an AND condition and expressed like this:您要做的实际上是一个 AND 条件,并表示如下:
function itemDelete(userId){
return (userId != '1.jpg') && (userId != '2.jpg');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.