【发布时间】:2020-11-03 10:24:55
【问题描述】:
这是我的数据库结构:
users (collection) -> user-docs (uid) -> wishlists (collection) -> wishlist-docs -> wünsche -> wünsche-docs
users 应该是 readable,适用于所有人,即使是未经授权的用户。
其他所有内容都应该仅对授权用户可读/可写。
这是我尝试过的:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow write: if request.auth != null;
}
match /{users} {
allow read;
}
match /{users}/documents/{allSubcollections=**} {
allow read: if request.auth != null
}
}
}
但这不起作用,因为read 有问题。我什么也看不懂。我在这里做错了什么?
编辑:
这就是我想要访问users的方式:
//MARK: check username
static func checkUsername(field: String, completion: @escaping (Bool) -> Void) {
let db = Firestore.firestore()
let collectionRef = db.collection(Keys.users)
collectionRef.whereField(Keys.username, isEqualTo: field).getDocuments { (snapshot, err) in
if let err = err {
print("Error getting document: \(err)")
} else if (snapshot?.isEmpty)! {
completion(false)
} else {
for document in (snapshot?.documents)! {
if document.data()[Keys.username] != nil {
completion(true)
}
}
}
}
}
如果用户未经授权,这也应该有效。其他一切都应仅限于授权用户。
【问题讨论】:
标签: ios firebase google-cloud-firestore firebase-security