【问题标题】:Firestore how to prevent creating new collections?Firestore 如何防止创建新集合?
【发布时间】:2021-12-12 08:41:37
【问题描述】:

我们知道如何编写安全规则来限制对集合的操作,但是,如何拒绝创建新集合?

【问题讨论】:

    标签: google-cloud-firestore firebase-security


    【解决方案1】:

    在您的安全规则中只允许写入特定集合是一个两步过程

    1. 顶楼disallow writing to any documents
    2. 然后有选择地允许在您想要允许的集合中写入文档。

    例如(只允许访问users 集合):

    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if false;
        }
        match /users/{userId} {
          allow read, update, delete: if request.auth != null && request.auth.uid == userId;
          allow create: if request.auth != null;
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 2020-03-23
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2021-11-14
      • 2019-09-07
      • 1970-01-01
      • 2021-10-30
      相关资源
      最近更新 更多