0

I’m trying to implement setting unique usernames in a sign up flow. Here’s how I try to match the username against the database:

refUsers.queryOrdered(byChild: "username").queryEqual(toValue: usernameText!).observeSingleEvent(of: .value, with: { snapshot in

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

              // Move to the next View of the flow.                      
              // Set the username.
      }
      else {
              print("Duplicate username.")
              self.usernameLabel.text = "Looks like the username is already taken."
      }

But this seems to behave abnormally. It would work checking against old usernames in the database, but it doesn’t match with the usernames recently stored. What’d be the right way to do this?

waseefakhtar
  • 1,373
  • 2
  • 24
  • 47
  • 1
    Is this function called before or after a user is authenticated? I was just wondering in terms of what your database rules would be. I've given a suggestion on addressing the problem of unique usernames before, which you can check out here: https://stackoverflow.com/questions/44932638/proper-way-to-maintain-unique-usernames-and-extra-profile-data-in-firebase/44933300#44933300 – Jen Person Jul 07 '17 at 20:43
  • The function is called before a user is authenticated. Is this the new right way to do it? I got the function deployed but I can’t get my head around how to implement this in Swift. I enter the webhook into the browser and I get "Error: could not handle the request”. Should I be getting a JSON when implemented within the app? – waseefakhtar Jul 08 '17 at 10:42

0 Answers0