如何使云Firestore auth Uid匹配userid?

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

Firestore docs中,一种推荐的编写安全规则的方法是

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

但是,当我创建用户时,userID与auth.uid不同(两者都是随机字符串,但完全随机)。

如何在创建新用户时自动匹配它们?

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

您显示的规则表明文档的ID应与Firebase身份验证获取的用户的UID相匹配。这是标准做法。如果您的代码也没有写入此文档,那么该规则将无法按预期运行。所以,你get the UID of the user并将其用作文档的ID。

© www.soinside.com 2019 - 2024. All rights reserved.