我試圖允許每個用戶使用 firestore 讀取和寫入他們自己的資料,但是我收到了權限不足的錯誤。我不確定為什么。
我的 Firestore 有這些規則。我只是想將用戶的 UID(存盤在 createdBy 屬性中)與 request.auth.uid 中可訪問的用戶 uid 進行比較
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /bots/{id} {
allow read, write: if request.auth != null && resource.data.createdBy == request.auth.uid;
match /order_history/{id} {
allow read, write: if request.auth != null && resource.data.createdBy == request.auth.uid;
}
}
}
}
還有我檢索資料的查詢:
const orders = await getDocs(query(collectionGroup(db, 'order_history'), orderBy('datetime'), where('createdBy', '==', user.uid)));
setOrders(orders.docs.map((doc) => ({
...doc.data()
})))
}
這是我的 Firestore 組織的概述:

我的前面回傳FirebaseError: Missing or insufficient permissions。
我做錯了什么?
uj5u.com熱心網友回復:
您正在執行一個集合組查詢,它需要這種型別的規則:
match /{path=**}/order_history/{id} {
allow read: ...
}
這是因為集合組索引資料庫中任何路徑的檔案,因此您還需要從任何路徑讀取該資料的權限。
另請參閱有關為集合組查詢定義安全規則的檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/498218.html
標籤:反应 火力基地 谷歌云火库 firebase-安全
