Firebase/Database - 版本 2 安全规则?
Firebase/Database - Version 2 Security Rules?
我刚刚开始使用 Firebase,请注意有很多 tutorials/docs 指示您将以下内容放入数据库规则中:
{
"rules": {
"$uid": {
".write": "$uid === auth.uid",
".read": "$uid === auth.uid"
}
}
}
但是,似乎有此代码的新版本,即版本 2。我想知道我上面的代码是否已过时且版本 1(我猜)与此代码基本相同:
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
来自 google firebase 文档 (https://firebase.google.com/docs/firestore/security/get-started)
谢谢
您显示的是两个彼此不直接相关的不同产品的规则。
您的第一个示例是针对 Firebase 实时数据库的。这种基于 JSON 的规则语言多年来一直没有改变。
您的第二个示例用于 Firestore。这是一种完全不同的安全规则语言,有点类似于 Firebase 实时数据库,但完全不同。
您所指的规则 "version 2" 仅适用于 Firestore。它改变了语言几个方面的行为,仅此而已。
我刚刚开始使用 Firebase,请注意有很多 tutorials/docs 指示您将以下内容放入数据库规则中:
{
"rules": {
"$uid": {
".write": "$uid === auth.uid",
".read": "$uid === auth.uid"
}
}
}
但是,似乎有此代码的新版本,即版本 2。我想知道我上面的代码是否已过时且版本 1(我猜)与此代码基本相同:
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
来自 google firebase 文档 (https://firebase.google.com/docs/firestore/security/get-started)
谢谢
您显示的是两个彼此不直接相关的不同产品的规则。
您的第一个示例是针对 Firebase 实时数据库的。这种基于 JSON 的规则语言多年来一直没有改变。
您的第二个示例用于 Firestore。这是一种完全不同的安全规则语言,有点类似于 Firebase 实时数据库,但完全不同。
您所指的规则 "version 2" 仅适用于 Firestore。它改变了语言几个方面的行为,仅此而已。