ios - 如何使云 Firestore auth Uid 匹配用户 ID?
问题描述
在Firestore 文档中,一种推荐的编写安全规则的方法是
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;
}
}
}
但是,当我创建用户时,用户 ID 与 auth.uid 不同(两者都是随机字符串,但完全随机)。
创建新用户时如何使它们自动匹配?
解决方案
您显示的规则表明文档的 ID 应与通过 Firebase 身份验证获得的用户的 UID 匹配。这是标准做法。如果您的代码也没有为此编写文档,那么该规则将无法按您的预期工作。因此,您获取用户的 UID并将其用作文档的 ID。
推荐阅读
- java - Check Leap Year - without using division operation
- mysql - composite index is not work in range query
- google-sheets - Format cells with RGBA colors via API calls
- kubernetes - 即使在 kubernetes 中公开服务后也无法连接到外部负载均衡器
- javascript - How do I format doc.writeln without using quotation marks
- javascript - ReactJS - execute a javascript code after the ajax function renders the data
- html - AngularJS 菜单布局桌面和移动响应
- java - Spring MySQL Profiler throws exception
- sparql - SPARQL: filter on both string and integer?
- android - 使用 TabLayout + ViewPager + Toolbar 来实现这个 Material Design 效果?