I want to check if the user uses the same email that already exists to sign up we'll tell the user "the email already exist" so let see the function that I created to do that but the status always return false please advise me also I'm new at Firebase thanks.
func checkUserExist(phoneOrEmail:String)-> Bool {
var isExistingUser = false
// collection "tm_members"
COLLECTION_USERS
.whereField("email", isEqualTo: phoneOrEmail)
.getDocuments() { (snapshot, error) in
if let err = error {
print("Error getting documents: \(err)")
} else {
for document in snapshot!.documents {
print("\(document.documentID) => \(document.data())")
let email:String = document.data()["email"] as! String
if !email.isEmpty {
isExistingUser = true
}
else{
isExistingUser = false
}
}
}
}
print("user status \(isExistingUser)")
return isExistingUser
}