I try to prevent the creation of already existing usernames.
This is my code where I upload usernames to the database:
ref?.child("users").child(FIRAuth.auth()!.currentUser!.uid).child("username").setValue(self.createUserName.text)
And this is the code where I try to get if the username already exists or not
ref?.child("users")
.queryOrdered(byChild: "username")
.queryEqual(toValue: self.createUserName.text?.uppercased())
.observeSingleEvent(of: .value, with: { (snapshot) in
if !snapshot.exists() {
print("")
}
}) { error in
print("")
}
The database looks like this
Database_App {
users {
-3bSRmS4PHXUwsr7XbMBwgPozNfK2 {
username: "sebas.varela"
}
}
}
And appear this line in the console:
Consider adding ".indexOn": "username" at /users to your security rules for better performance
The problem is that I always get . What is the problem with this?