![](/img/trans.png)
[英]Firestore `addDoc()` function seems to resolve before the doc is created
[英]firestore how to check for the doc owner before write?
在允許用戶創建之前如何檢查文檔所有者? 腳步:
document.owner
在發布時給我錯誤。
//only allow create in moviesCommentID/{document} when document is owned by the user
match /moviesCommentID/{document=**} {
allow create: if request.auth != null && document.owner == request.auth.uid;
}
任何幫助是極大的贊賞。
規則中的document
變量是一個字符串,其值是文檔 ID。
Firestore 沒有任何文檔所有者的內置概念。 但是如果您在文檔數據中有一個owner
字段,您可以在您的規則中以resource.data.owner
的身份訪問它。 另請參閱 Firebase 有關安全規則中數據驗證的文檔。
1- 創作
您需要在要更改的Firestore
文檔中有一個字段來存儲所有者 uid
allow create: if request.auth != null && resource.data.ownerUid == request.auth.uid;
2-更新:
使用與“創建”相同的方法(所有者實際上是登錄的人),但還要添加一些內容來說明他們不能將所有者更改為另一個用戶
allow update: if request.resource.data.ownerUid== resource.data.ownerUid;
請注意, request.resource
變量包含文檔的未來 state
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.