【发布时间】:2020-10-18 08:32:35
【问题描述】:
我在控制台中收到此错误
[Firebase/Database][I-RDB038012] /people/cQEVsQGXS3VJQzPBU4nL1HLx0Kq2 的侦听器失败:permission_denied
以下是我的规则。我知道错误可能出在 uid 上,因为我收到了控制台消息,但我不确定。我使用 firebase 文档试图弄清楚如何编写规则。
{
"rules": {
"people" : {
"$uid": {
"Education" :{
".read": "auth.uid != null"
,".write": "$uid == auth.uid"
}
,"Coordinates" : {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"ForReUpload": {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"PhotoPosts": {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"WhatIamConsideringBuying": {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"caption": {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"peopleWhoLike" : {
".read": "$uid == auth.uid",
".write": "auth.uid != null"
}
,"peopleWhoLike2" : {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
,"postID" : {
".read": "auth.uid != null",
".write": "$uid == auth.uid"
}
,"users" : {
".read": "$uid == auth.uid",
".write": "$uid == auth.uid"
}
}
}
}
}
这是我的数据库的 JSON:
"people" : {
"1ZWT7FAE2qThNQfBj7tbMO7BnMo1" : {
"Coordinates" : {
"latitude" : 50.054738,
"longitude" : 8.226809826085624
"peopleWhoLike2" : {
"1vLVFwrXrHUoakmDrnQKwbv08Yj1" : 1581548952597,
"F9NX0UCG4fVHCKFk2VZ1NZKsLro2" : 1586210112155,
"IrrBgFY9C1ekMmHUkQRzc5LhbDu1" : 1581547417432,
触发查询:
let thisUsersUid = Auth.auth().currentUser?.uid //Mr. Dunn's uid
refArtists = Database.database().reference().child("people");
refArtists.observe(DataEventType.value, with: {snapshot in
if snapshot.childrenCount>0{
self.people.removeAll()
for people in snapshot.children.allObjects as! [DataSnapshot] {
if people.key != thisUsersUid {
print("peoplekey",people.key)
let peopleObject = people.value as? [String: AnyObject]
let peopleEducation = peopleObject?["Education"] as? String
let locCoord = CLLocation(latitude: lat, longitude: lon)
let distance = locCoord.distance(from: self.dict)
print(distance, "distancexy")
....
self.people.append(peopl)
.....
self.people.sort { ($0.distance ?? 0) < ($1.distance ?? 0) }
print("aaaaaaaa", self.people.map {$0.distance})
self.table.reloadData()
}
}
【问题讨论】:
-
请编辑问题以显示失败的查询,以及您希望它执行的操作。应该清楚您的查询如何与您的规则匹配。
标签: swift firebase firebase-realtime-database firebase-security