【问题标题】:What's the difference between Firestore Rules and Firestorage Rules?Firestore 规则和 Firestore 规则有什么区别?
【发布时间】:2019-04-18 19:03:27
【问题描述】:

我有文件要确保安全,一旦管理员将文件上传到存储中,只有他和与他共享文件的用户才能访问下载该文件的链接。因此,根据 Firestore 规则,我添加了以下内容:

match /users/{userID} {
  		allow read: if isOwner(userID) || isAdmin();
  		allow write: if isOwner(userID) || isAdmin();
		}
    
    /// FUNCTIONS BELLOW ///
    
    function isAdmin() {
     return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.IsAdmin;
    }

但是,当我尝试在 Firestorage 下添加相同的规则时,访问总是被拒绝。

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if isAdmin();
  		allow write: if isAdmin();
    }
    
     /// FUNCTIONS BELLOW ///
    
    function isAdmin() {
     return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.IsAdmin;
    }
  }
}

Firestorage get 方法与 Firestore get 方法的工作方式不同吗? 任何帮助将不胜感激。

【问题讨论】:

    标签: firebase firebase-realtime-database google-cloud-firestore


    【解决方案1】:

    没有Firestorage Rules,实际上有Cloud Firestore 的规则,它是Google 的新数据库,Firebase Storage 用于存储图像、音频、视频或其他用户生成的内容以及 Fireabse 实时数据库,它也是一个 NoSQL 数据库。

    安全规则以简单而富有表现力的格式提供访问控制和数据验证。

    存储安全规则用于确定谁对存储在 Cloud Storage 中的文件具有读写权限,以及文件的结构以及它们包含哪些元数据。

    Firebase 实时数据库规则确定谁对您的数据库具有读写权限、您的数据的结构方式以及存在哪些索引。这些规则存在于 Firebase 服务器上,并始终自动执行。

    【讨论】:

    • 嘿克劳迪奥。我可以帮助您了解其他信息吗?如果您认为我的回答对您有所帮助,请考虑采纳(✔️)。我真的很感激。谢谢!
    【解决方案2】:

    我猜你说的是Firebase Cloud StorageFirestore

    您的 Cloud Storage 规则的问题是您无法访问 Firestore 数据库。如果您需要传递数据以协助授权写入,您可以查看custom claims,您可以在安全规则中使用auth.token.admin === true 访问它,例如查看管理员属性的用户身份验证令牌

    service firebase.storage {
      match /b/{bucket}/o {
        match /{allPaths=**} {
          allow read: if isAdmin();
          allow write: if isAdmin();
        }
    
        /// FUNCTIONS BELLOW ///
    
        function isAdmin() {
          return auth.token.admin === true
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 2018-10-19
      • 2019-08-14
      相关资源
      最近更新 更多