所以我在這里有這些firestore規則:
match /Customers/{customerId} {
allow read, update, create, delete: if request.auth != null && get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.businessId in resource.data.businessIds || request.auth != null && request.auth.uid == resource.data.uid || request.auth != null && get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.businessId == resource.data.businessId || request.auth != null && get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.customerId == resource.data.customerId;
match /ServiceLocations/{ServiceLocationId} {
allow read, update, create, delete: request.auth != null && get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.businessId == resource.data.businessId;
}
}
由于某種原因,當我在 /Customers/{customerId} 層次結構中呼叫 /ServiceLocations/{ServiceLocationId} 時,我獲得了無效權限。但我很困惑,因為路徑和價值觀是正確的。我能夠很好地閱讀 customerId 檔案,因此那里沒有問題,但具體而言,我無法閱讀 serviceLocationId 檔案,該檔案是 customerId 檔案中的 ServiceLocations 子集合中的檔案。
get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.businessId
是回傳 businessId 的有效路徑。
resource.data.businessId
并且 businessId 是 serviceLocationId 檔案中的有效欄位,并且兩個值實際上彼此相等。然而它仍然回傳錯誤。
附件是兩個影像,顯示了我發送請求的用戶的“用戶”檔案,其中包括 businessId 欄位,以及我嘗試從中讀取的 serviceLocationId 檔案,其中還包括 businessId 欄位。正如您所看到的,這兩個值實際上都匹配并且路徑是正確的。
https://i.stack.imgur.com/vJNPN.png
https://i.stack.imgur.com/W8sgM.png
以下是其中一個請求被稱為無效的示例:
db.collection("Customers")
.doc(selectedCustomerData.customerId)
.collection("ServiceLocations")
.onSnapshot((snapshot) => {
我只是做錯了什么嗎?對我來說完全是無稽之談。任何幫助,將不勝感激。
uj5u.com熱心網友回復:
我懷疑這是安全規則無法為您過濾資料的情況。
具體來說,我認為規則可能無法自行執行此要求:
get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.businessId ==
resource.data.businessId;
嘗試在查詢中傳遞一個過濾器,同時傳遞用戶的企業 ID ( .where('businessId', '==', 'The business ID of the user')),或者將企業 ID 作為自定義宣告傳遞,而不是在檔案中查找它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/523522.html
