Firebase 如何比较数据规则中的变量(== vs ===)?
How does Firebase compares a variable (== vs ===) in Data Rules?
Information that is given below is straight from Firebase website.
{
"rules": {
"users": {
"$user": {
".read": "auth.uid === $user",
".write": "auth.uid === $user"
}
}
}
}
When a client tries to access /users/barney, the $user default
location will match with $user being equal to "barney". So the .read
rule will check if auth.uid === 'barney'. As a result, reading
/users/barney will succeed only if the client is authenticated with a
uid of "barney".
Firebase 擅长记录,但我没有找到任何关于使用“==”或“===”的深入讨论。据我所知,它的工作原理与 JavaScript 一样。
根据他们的文档
if auth.uid === 'barney'. As a result, reading
/users/barney will succeed only if the client is authenticated with a
uid of "barney".
有时我见过
"$user": {
".read": "auth.uid == $user",
".write": "auth.uid == $user"
}
所以我的问题是哪一个是正确的方法?当我们在规则中使用“==”和“===”时会发生什么?
我认为 Firebase 将所有 === 视为 ==(同样将所有 !== 视为 !=)。
我的证据是 Bolt Compiler 将 bolt 文件中的三重运算符转换为规则 JSON 输出中的双重运算符。
如果您查阅 Firebase 数据库安全规则 API documentation, you will see the following definitions for equals:
=== (equals)
...
Note:: == IS TREATED AS ===. If you use == in your security rules, it will be translated to === when the rules are run.
和 not equals:
!== (not equals)
...
Note: != IS TREATED AS !==. If you use != in your security rules, it will be translated to !== when the rules are run.
Information that is given below is straight from Firebase website.
{
"rules": {
"users": {
"$user": {
".read": "auth.uid === $user",
".write": "auth.uid === $user"
}
}
}
}
When a client tries to access /users/barney, the $user default location will match with $user being equal to "barney". So the .read rule will check if auth.uid === 'barney'. As a result, reading /users/barney will succeed only if the client is authenticated with a uid of "barney".
Firebase 擅长记录,但我没有找到任何关于使用“==”或“===”的深入讨论。据我所知,它的工作原理与 JavaScript 一样。
根据他们的文档
if auth.uid === 'barney'. As a result, reading /users/barney will succeed only if the client is authenticated with a uid of "barney".
有时我见过
"$user": {
".read": "auth.uid == $user",
".write": "auth.uid == $user"
}
所以我的问题是哪一个是正确的方法?当我们在规则中使用“==”和“===”时会发生什么?
我认为 Firebase 将所有 === 视为 ==(同样将所有 !== 视为 !=)。
我的证据是 Bolt Compiler 将 bolt 文件中的三重运算符转换为规则 JSON 输出中的双重运算符。
如果您查阅 Firebase 数据库安全规则 API documentation, you will see the following definitions for equals:
=== (equals)
...
Note:: == IS TREATED AS ===. If you use == in your security rules, it will be translated to === when the rules are run.
和 not equals:
!== (not equals)
...
Note: != IS TREATED AS !==. If you use != in your security rules, it will be translated to !== when the rules are run.