如何将 Firestore 更新限制为与用户的“pageID”自定义声明匹配的文档?

问题描述 投票:0回答:1

我对用户数据的设计本质上是当我对用户进行身份验证时,他们有一个名为“pageID”的字段。 pageID 允许用户仅更改该字段与其相应文档 ID 匹配的特定页面。

在 Retrospec 中,我应该设计不同的用户数据,但现在我想知道确保只有具有该特定 pageID 字段的用户才能更改其分配的文档的最佳方法。

用户(集合)-> 用户 ID -> [pageID, email] 页面(集合)-> pageID -> [要编辑的各个字段]

谢谢!

我尝试使用身份验证令牌,但没有成功

firebase google-cloud-firestore firebase-security
1个回答
0
投票

请尝试让我知道。

    service cloud.firestore {
        match /databases/{database}/documents {
          match /users/{userID}/pages/{pageID} {
            
            allow read, write: if request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.pageID == pageID
    
          }
        }
}
© www.soinside.com 2019 - 2024. All rights reserved.