Firebase/数据库 - 版本 2 安全规则?

Eva*_*van 6 security rules firebase firebase-security firebase-realtime-database

我刚刚开始使用 Firebase,并注意到有很多教程/文档指示您将以下内容放入数据库规则中:

{
  "rules": {
    "$uid": {
      ".write": "$uid === auth.uid",
      ".read": "$uid === auth.uid"
   }
 }
}
Run Code Online (Sandbox Code Playgroud)

但是,似乎有此代码的新版本,第 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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

来自 google firebase docs ( https://firebase.google.com/docs/firestore/security/get-started )

谢谢

Dou*_*son 8

您正在显示来自彼此不直接相关的两种不同产品的规则。

您的第一个示例适用于 Firebase 实时数据库。这种基于 JSON 的规则语言多年来没有改变。

您的第二个示例适用于 Firestore。这是一种完全不同的安全规则语言,与 Firebase 实时数据库有点相似,但完全不同。

您所指的“版本 2”规则仅适用于 Firestore。它改变了语言的几个方面的行为,仅此而已。