[英]Firebase storage rules, leave on path open
現在 firebase 已經強制使用規則加擾來找到正確的解決方案。 我在主桶中有所有圖像,每個登錄后的用戶都有類似桶的東西
users/{uid}/uploads
所有上傳的照片 go(在某些時候限制為圖像會很酷)這些應該是公開讀寫的,如果寫入只能用於經過身份驗證的用戶就更好了,但是需要授權閱讀。
在用戶通過身份驗證之前有一個特殊的文件夾,需要上傳個人資料照片
users/uploads
我所擁有的應該是公開的,但第二條規則優先
service firebase.storage {
match /b/{bucket}/o {
match /users {
match /uploads {
match /object {
allow read, write
}
}
}
match /{allPaths=**} {
allow read, write: if request.auth != null
}
}
}
我認為它可能需要不是 /users/uploads 然后執行此操作,但文檔對 if else 語句不利。 有什么想法嗎?
編輯:此規則集適用於正確閱讀,但在注冊期間未經身份驗證時仍無法寫入
service firebase.storage {
match /b/{bucket}/o {
// Allow only authenticated users to upload
// Any user can read
match /users/uploads {
allow read, write;
}
// Only allow user with auth.uid == uid to read/write
match /users/{uid}/uploads {
allow read: if true;
allow write: if request.auth.uid == uid;
}
}
}
您可以嘗試以下規則,這些規則將限制對用戶自己的目錄的訪問,並且還有一個公用文件夾:
rules_version="2";
service firebase.storage {
match /b/{bucket}/o {
// Allow only authenticated users to upload
// Any user can read
match /users/uploads {
allow read: if true;
allow write: if request.auth != null;
}
// Only allow user with auth.uid == uid to read/write
match /users/{uid}/uploads {
allow read: if true;
allow write: if request.auth.uid == uid;
}
}
}
請注意if request.auth;= null;
允許每個人寫(包括刪除)所以嘗試使用allow create:
only。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.