简体   繁体   English

Firebase-权限被拒绝的Swift

[英]Firebase - Permission Denied Swift

I am trying to check the Firebase database for existing values, then I get permission denied. 我试图检查Firebase数据库中的现有值,然后获得拒绝权限。 This primarily is triggered due to permissions on the database. 这主要是由于对数据库的权限而触发的。 Although I changed them, yet it doesn't seem to solve the issue. 尽管我更改了它们,但似乎无法解决问题。 The structure I have is the following: 我的结构如下:

在此处输入图片说明

I have the following functions to check if the mobile number or username are taken when registering the user: 我具有以下功能来检查在注册用户时是否使用了手机号码或用户名:

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)
            }
        })

    }

And added the permissions in the database as following: 并在数据库中添加了如下权限:

{
  "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"
      }
  }
}

Yet whenever I execute the usernameValidation function above or mobileValidation function above, I get permission denied. 但是,每当我执行上面的usernameValidation函数或上面的mobileValidation函数时,我都会被拒绝权限。 What am I missing out? 我错过了什么? Is this something still to do with permissions? 这仍然与权限有关吗?

Thanks, 谢谢,

I had the same issue; 我遇到过同样的问题; I solved it by login-in a user to access the Firebase. 我通过登录用户访问Firebase解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM