![](/img/trans.png)
[英]In Firestore, how to get the uid of Firebase Authentication to be a document?
[英]How to match a user's uid stored in document field inside Firebase security rule for Firestore
我想根據請求數據的用戶的 UID 檢查存儲在文檔(名為premiumID的父集合)的文檔字段中的 UID。 簡單來說,我希望用戶只訪問包含他的 UID 的文檔。
這是我到目前為止所做的
service cloud.firestore {
match /databases/{database}/documents {
match /premiumID/{docId} {
function userData() {
return resource.data.uid
}
allow update: if userData() == request.auth.uid;
allow delete: if userData() == request.auth.uid;
allow create: if request.auth.uid != null;
allow read: if userData() == request.auth.uid;
}
}
}
這是我的數據庫的樣子-
這是我測試它的方式。 這讓我讀寫被拒絕。
規則allow write: if request.auth.uid == request.resource.data.uid;
檢查用戶身份驗證是否與文檔包含的字段uid
相同。 但正如您的問題評論中所說,您的集合名稱與您使用的規則不匹配。
檢查此站點,它包含有關 Firebase 規則的非常有用的信息。 當我開始使用 firebase 規則來處理更復雜的規則時,它真的幫助了我。
我想如果你想匹配一個文檔,你必須使用{document}
而不是{docId}
。 我也有類似的問題,改成{document}
解決了。
match /pID/{document}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.