Learn Courses My Dashboard

FireBase name check authenticity

Hello there, since today I am encountering a little problem with my data base when I want to verify if a name is taken or not.

Here is the code:

func checkAuthenticity(completion: @escaping () → Void ) {

    let db = Firestore.firestore()
    //let user = UserService.shared.user
    let ref = db.collection("users")
    var query = ref.whereField("First Name", in: [firstname])
   
    
    //Get the documents, if there are some
    query.getDocuments { snapshot, error in
        
        guard error == nil else {
            print(error)
            errorStatementOne = false
            return
        }
        if snapshot != nil {
        print(snapshot!.count)
        }

        if snapshot!.count > 1 {
            errorStatementOne = false
        }
    }
    
    query = ref.whereField("Second Name", in: [secondname])
    query.getDocuments { snapshot, error in
        
        guard error == nil else {
            print(error)
            errorStatementTwo = false
            return
        }
        
        if snapshot != nil {
        print(snapshot!.count)
        }
        
        if snapshot!.count > 1 {
            errorStatementTwo = false
        }

    }
    
    print("Error statement one is \(errorStatementOne)")
    print("Error statement two is \(errorStatementTwo)")
    
    completion()
}

And THE strange thing is both snapshots are showing that they are much more bigger than 1, BUT, errorStatementOne and Two are true. Strange right?

This is how my Data base rules look like:

rules_version = ‘2’;
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write, delete: if request.auth != null;
}
}
}

Please provide me some help as soon as possible, I am really stuck here