I am relatively new to working with Firebase and despite searching around cannot find the answer to my problem so was hoping someone could help.
I have a function that is designed to check if a user already exists within the databases "Users" collection. The function makes a call to where the user record would be and what I would like to happen is for it to return "true" if a record is found or "false" if one isn't.
However, I think (correct me if I'm wrong) the "getDocument" method hasn't finished running and therefore hasn't updated the variable when the return statement is read, therefore the function always returns false.
Does anyone have a way to ensure the "userStatus" variable can be updated before the function returns - or a different way of achieving the functions objective.
Thanks in advance!
static func checkUserProfile(currentUserID:String) -> Bool {
let userRecord = db.collection("Users").document(currentUserID)
var userStatus = false
userRecord.getDocument { docSnap, error in
if error == nil {
if docSnap != nil {
userStatus = true
}
}
}
return userStatus
}