【发布时间】:2018-08-09 11:22:58
【问题描述】:
我正在开发一个应用程序,让教师可以记录学生的课程。使用 Firebase 规则我想允许教师访问某些学校。我有以下规则:
{
"rules": {
"Schools" : {
"$schoolId" : {
".read" : "data.child('Teachers').hasChild(auth.uid)",
".write" : "data.child('Teachers').hasChild(auth.uid) ||
root.child('User').child(auth.uid).child('Invitation').exists()"
}
},
"Users" : {
"$uid" : {
".read" : "auth.uid === $uid",
".write": "auth.uid === $uid"
}
}
}
}
在模拟器中一切正常,但是当触发以下所有权限时,所有学校都被拒绝。
DataService.ds.REF_SCHOOLS.observeSingleEvent(of: .value) { (snapshot) in
MySchools.mySchoolKeyList.removeAll()
MySchools.mySchoolList.removeAll()
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshot {
if let recordDict = snap.value as? Dictionary<String, AnyObject> {
if let name = (recordDict["SchoolName"] as? String) {
MySchools.mySchoolList.append(name)
}
MySchools.mySchoolKeyList.append(snap.key)
}
}
if MySchools.mySchoolList.isEmpty {
MySchools.mySchoolList.append("You do not belong to any schools.")
}
}
}
以下是 Firebase 数据库的快照供参考:
有人知道我的规则有什么问题吗?也将不胜感激如何处理权限被拒绝的结果。
【问题讨论】:
-
是
DataService.ds.REF_SCHOOLS指向Schools还是School/Some_school_ID? -
指向 Database.database().reference().child("Schools")
标签: ios swift firebase firebase-realtime-database firebase-security