我一直收到來自 Firebase 的電子郵件,說我的安全規則是安全的,所以我必須找到如何保護它們的正確方法。
Not recommended:
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
推薦:
service cloud.firestore {
match /databases/{database}/documents {
// Assign roles to all users and refine access based on user roles
match /some_collection/{document} {
allow read: if request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == "Reader"
allow write: if request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == "Writer"
// Note: Checking for roles in your database using `get` (as in the code
// above) or `exists` carry standard charges for read operations.
}
}
}
就在我嘗試了推薦的規則之后,我的應用程式停止為經過身份驗證的用戶作業,我不得不保留不安全的規則以允許用戶重新使用該應用程式......有誰知道為什么會發生這種情況?
uj5u.com熱心網友回復:
嘗試這個
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /your_collecton_name/{your_documents} {
allow read,write: if request.auth != null
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/357711.html
標籤:火力基地 安全 谷歌云firestore 火力基地安全 规则
