ios - 如何使云 Firestore 身份验证 Uid 与用户 ID 匹配?

标签 ios swift firebase google-cloud-firestore firebase-security

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 不同(两者都是随机字符串,但完全随机)。

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

最佳答案

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

关于ios - 如何使云 Firestore 身份验证 Uid 与用户 ID 匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55330996/

相关文章:

ios - 如何从 iPhone 模拟器访问主机本身

iphone - EXC_BAD_ACCESS 与 NSFetchedResultsController

swift - 随机生成两个节点

ios - swift 和火力地堡 : Retrieving location data from Firebase to show on Google map marker

ios - 呈现模态视图 Controller 时暂停动画

ios - 在不破坏表格 View 单元格点击功能的情况下关闭 iOS 键盘

swift - 如何使用 Swift 在 FireBase 数据库中发生更改时获取计数值?

javascript - 如何在用户登录时显示注销

javascript - 下一个代码块在获取之前更早执行我该如何解决这个问题

ios - 使用 AutoLayout 查看两个位置