0
これは、特定のユーザーが割り当てられた「ショップ」オブジェクトにアクセスすることを許可する方法に関する私のアプローチです。Firebase:ユーザーに応じて異なるセクションへのアクセス
func shopFetch() {
self.shop.removeAll()
let shopRef = FIRDatabase.database().reference().child("shop").child(someIDforShop).child("menu")
shopRef.observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let something1 = dictionary["some1"]
let something2 = dictionary["some2"]
let shopper = Shop(some1: something1, some2: something2)
self.shop.insert(shopper, at: 0)
self.collection.reloadData()
}
}, withCancel: nil)
}
これらは
rules: {
"users": {
"$uid": {
".read": "auth != null || auth.uid == $uid",
".write": "auth != null && auth.uid == $uid",
"$yourShop": {
".read": "true"
}
},
"shop": {
"$yourShop": {
".read": "root.child('users').child(auth.uid).child($yourShop).val() == true",
".write": "root.child('users').child(auth.uid).child($yourShopManager).val() == true || root.child('users').child(auth.uid).child('isAdmin').val() == true"
}
},
}
私のセキュリティルールあるのは、私は私のデータベースでこれを持っているとしましょう:
<app-name>: {
"shop": {
"shop1": {
"menu": {
"some1": "thing1",
"some2": "thing2"
}
},
"shop2": {
"menu": {
"some1": "thing1",
"some2": "thing2"
}
},
"shop3": {
"menu": {
"some1": "thing1",
"some2": "thing2"
}
},
"users": {
"K4of4ofp32kfoE": {
"shop": {
"shop1": true
}
},
"fj3i53ogF34oGf329ieQ": {
"shop": {
"shop2": true
}
},
}
私はsomeIDforShop
にlet shopRef
に何を書くべきですか? これを行うと、各ユーザーは自分の「ショップ」にアクセスできます。私はchildByAutoID()
を試しました。ルールに指定されているように、ユーザーに関連するデータを取得するものと仮定しています。しかしは何も返しません。print(snapshot)