【发布时间】:2018-03-31 15:50:41
【问题描述】:
我正在尝试检查 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 函数时,我都会被拒绝权限。我错过了什么?这仍然与权限有关吗?
谢谢,
【问题讨论】:
-
错误信息不言自明,它是PERMISSION DENIED。
-
我知道@ldindu 以及我在问什么仍然可能导致这种情况,因为我知道这是权限被拒绝错误。我什至分享了期待一些反馈的规则
-
auth == null 只会在它为 null 并且是您所期望的情况下才会返回 true,您不应该检查“auth != null”吗?
-
如果在此处添加了 auth!= null,这意味着除非用户通过身份验证,否则我将无法进行检查。由于这是在注册中使用的,因此用户未经过身份验证。
标签: ios swift firebase firebase-realtime-database