Firebase 使用当前用户ID(auth.uid)在文档中设置createdBy字段
我知道Firebase有Firebase 使用当前用户ID(auth.uid)在文档中设置createdBy字段,firebase,google-cloud-firestore,firebase-authentication,firebase-security,Firebase,Google Cloud Firestore,Firebase Authentication,Firebase Security,我知道Firebase有FieldValue类,可用于在编写文档时生成服务器端时间戳() 将当前用户的uid插入文档的首选做法是什么 让客户机提供该字段似乎允许误用—除非我提供了一个服务器规则来检查(新的/更新的)文档以匹配请求.auth.uid,类似于: service cloud.firestore { match /databases/{database}/documents { match /broadcasts/{broadcast}/chatMessagesCollect
FieldValue
类,可用于在编写文档时生成服务器端时间戳()
将当前用户的uid插入文档的首选做法是什么
让客户机提供该字段似乎允许误用—除非我提供了一个服务器规则来检查(新的/更新的)文档以匹配请求.auth.uid
,类似于:
service cloud.firestore {
match /databases/{database}/documents {
match /broadcasts/{broadcast}/chatMessagesCollection/{message} {
allow write: if request.resource.data.uid == request.auth.uid;
allow read: if true;
}
}
}
我在web上找不到任何关于使用编写文档的用户填充文档的用例的东西,那么最好的解决方法是什么呢?现在使用安全规则来强制执行提供的UID与当前用户匹配正是正确的做法。没有比这更好的了(对于这个特定的用例),这是一个常见的实践 我甚至在这个博客系列中写到: