I have been searching a while and I could not find a solution -> me opening a new thread.
I am making this register page which works with a token send to the users email, it has to be checked against the values in the database, however (in code below) it prints "false" before "hi", I have been trying to get it async, but it doesn't want to work. Can someone help me out? Thanks!
PS: The selection variable makes my app go to the next page in registration, which, because return is false, won't go to.
public static func tokenVerify(_ token: String) -> Bool{
// Get database
let db = Firestore.firestore()
let collection = db.collection("tokens")
let query = collection.whereField("token", isEqualTo: token)
// Make response
var response = false
// Get all documents
query.getDocuments { snapshot, error in
// Check for errors,
if error == nil{
// No error
if let snapshot = snapshot {
if snapshot.isEmpty {
print("No token in database")
} else {
response = true
print("hi")
}
} else {
print("Unknown Error")
}
} else {
print("Error retrieving documents.")
}
}
print(response)
return response
}
Main View:
DispatchQueue.main.async{
if Registration.tokenVerify(token) {
selection = "third"
}
}