working on some FirAuth
things, but for some reason I can't figure out how to check if the users proposed email address has already been taken. I've tried calling .fetchProvidersForEmail
as suggested in other questions from a while back, but for whatever reason it just won't work. Also, I'm very green when it comes to completion handlers, so any constructive criticism on that would be welcome as well. So, for now, the parts of my code that pertain to this are:
import UIKit
import Firebase
class LoginViewController: UIViewController {
var reply : Bool = true
@IBOutlet weak var emailTxt: UITextField!
@IBAction func nextScreen(sender: UIButton) {
print(emailCheck(emailTxt.text!))
}
func emailCheck(input : String)->Bool{
let pullEmails = FIRAuth.auth()!.fetchProvidersForEmail(input, completion:{
result,error in
var decision : Bool = true
if error == "nil" {
print(error)
self.reply = true
}else{
print(error)
self.reply = false
}
})
return reply
}
}
So what happens with this is that reply always prints true
, probably because I explicitly defined it to at the top. Either way, it is almost as if the completion handler isn't waiting to actually be completed before it returns
the value. I've tried to figure out how to use them, as well as AsyncTasks
, but I was wondering if there was a simple error I've made in here that could solve this. Thanks everybody!