我希望所有經過身份驗證的用戶都能讀取該集合,但只有具有在 named 欄位中指定的 uid 的用戶uid才能寫入。
service cloud.firestore {
match /taken/{doc}{
allow read: if request.auth.uid != null;
allow read,write: if request.auth.uid == doc.id;
}
}
}
但是,即使查詢具有正確的 uid,上面的代碼也不允許寫訪問。
uj5u.com熱心網友回復:
嘗試這個:
service cloud.firestore {
match /taken/{doc}{
allow read: if request.auth != null;
allow create: if true; // resource.data is not defined on create, hence the separate case
allow update, delete: if request.auth.uid == resource.data.uid;
}
}
}
您甚至uid可以create根據您的邏輯強制將欄位設定為 on :
service cloud.firestore {
match /taken/{doc}{
allow read: if request.auth != null;
allow create: if request.auth.uid == request.resource.data.uid; // Forces uid to be set to the user's uid
allow update, delete: if request.auth.uid == resource.data.uid;
}
}
}
uj5u.com熱心網友回復:
你可以閱讀的使用檔案之中訪問資料resource為中解釋物件的檔案。
service cloud.firestore {
match /taken/{doc}{
allow read: if request.auth != null;
allow write: if request.auth.uid == resource.data.id;
}
}
}
上述規則允許任何經過身份驗證的用戶讀取“taken”集合中的檔案,但只有檔案中具有該 UID 的用戶才能寫入它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/333929.html
