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?