我已经阅读了所有关于此的谷歌文档,但它似乎仍然无法正常工作。我正在设置 firebase 规则,当我使用以下规则时,没问题我可以在用户通过身份验证时相应地读/写:
{
"rules": {
"Users": {
".write": "auth.uid != null",
".read": "auth.uid != null"
},
},
}
但是,当我使用以下内容时,我的权限被拒绝:
{
"rules": {
"Users": {
"$uid":{
".write": "auth.uid === $uid",
".read": "auth.uid === $uid"
},
},
},
}
这是我的数据库:
Users
-tnRYoVw1duUKV30VgtOxUTvb5kb2
FirstName: "Mike"
LastName: "Smith"
myuser: "msmith"
-saUXlTt5ioLNB33Iii9rHCdq4ov6
FirstName: "John"
LastName: "Heart"
myuser: "jheart"
这是来自 swift 的读取查询:
override func viewDidAppear(_ animated: Bool) {
ref = Database.database().reference()
ref?.child("Users").queryOrdered(byChild: "myuser").queryEqual(toValue: emailtextfield.text).observe(.value, with: { (snapShot) in
if (snapShot.value! is NSNull) {
print("nothing found")
} else {
let snapShotValue = snapShot.value as! [String:[String:Any]]
Array(snapShotValue.values).forEach {
let theFirstName = $0["FirstName"] as! String
let theLastName = $0["LastName"] as! String
self.firstName.text = theFirstName
self.lastName.text = theLastName
}
}
})
}
感谢您提供的任何帮助,告诉我我哪里做错了,伙计们。
最佳答案
Users 下的那些键看起来不像 Firebase Auth UID。它们看起来像实时数据库推送 ID。如果它们不是实际的 UID,那么您的规则将不起作用。
关于swift - Firebase 规则 - 仅限于特定用户还是仅在获得授权的情况下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56572710/