Listener at /users failed: permission_denied

Viewed 3810

I have a Sign Up Flow using Firebase. When I check if an email already exists in the database, like so:

refUsers.queryOrdered(byChild: "email").queryEqual(toValue: emailText).observeSingleEvent(of: .value, with: { snapshot in

      if (snapshot.value is NSNull) {
            print("Unique email")

            // Move to Password View.
            let passwordViewController = self.storyboard?.instantiateViewController(withIdentifier: "PasswordViewController") as! PasswordViewController

            self.navigationController?.present(passwordViewController, animated: true, completion: nil)

            // Pass the emailText to the last View of the flow.
            self.singleton.sharedInstance.emailText = emailText!

      }
      else {
            print("Duplicate email")
      }  
})

The problem is, I don't have the permission to view /users in the database cause my rule is:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

I know I can find if an email is a duplicate using Auth.auth().createUser but it's not just email that I'm checking in the sign up flow. I use the same method for unique username, as well. How can I achieve this?

2 Answers
Related