我正在尝试检查Firebase数据库中的现有值,然后我获得了权限被拒绝。这主要是由于数据库的权限而触发的。虽然我改变了它们,但似乎并没有解决这个问题。我的结构如下:
我有以下功能来检查注册用户时是否使用手机号码或用户名:
func usernameValidation(completion: (result: Bool) -> Void)
{
print("Inside usernameValidation")
dbReference.child("usernamesTaken").queryOrderedByValue().queryEqualToValue(self.usernameTxtField.text!).observeEventType(.Value, withBlock: { (snapshot: FIRDataSnapshot!) -> Void in
if(snapshot.childrenCount == 0 || snapshot == nil)
{
print("result is true in username validation")
//Username Available
completion(result:true)
}else{
print("result is false in username validation")
//Username Taken
completion(result:false)
}
})
}
func mobileValidation(completion: (result: Bool) -> Void)
{
dbReference.child("mobilesTaken").queryOrderedByValue().queryEqualToValue(self.mobileTxtField.text!).observeEventType(.Value, withBlock: { (snapshot: FIRDataSnapshot!) -> Void in
if(snapshot.childrenCount == 0 || snapshot == nil)
{
//mobile Available
completion(result:true)
}else{
//mobile Taken
completion(result:false)
}
})
}
并在数据库中添加了如下权限:
{
"rules": {
".read": "auth == null",
".write": "auth == null",
"usernamesTaken": {
".indexOn": ".value",
".read": "auth == null",
".write": "auth == null"
},"mobilesTaken": {
".indexOn": ".value",
".read": "auth == null",
".write": "auth == null"
}
}
}
然而,每当我执行上面的usernameValidation函数或上面的mobileValidation函数时,我都会被拒绝。我错过了什么?这是否与权限有关?
谢谢,
答案 0 :(得分:-1)
我有同样的问题;我通过登录用户访问Firebase解决了这个问题。