Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Last active April 4, 2021 07:32
Show Gist options
  • Save KrauserHuang/9e66ca2a886115c12f0fa5d8d6b9fd9c to your computer and use it in GitHub Desktop.
Save KrauserHuang/9e66ca2a886115c12f0fa5d8d6b9fd9c to your computer and use it in GitHub Desktop.
@IBAction func loginPressed(_ sender: UIButton) {
let error = validateTextField()
if error != nil {
popAlert(title: "Error occured", message: error!, alertTitle: "OK") { (action) in
self.emailTextField.text = ""
self.passwordTextField.text = ""
}
} else {
if let email = emailTextField.text,
let password = passwordTextField.text {
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
// remove [weak self] & guard let strongSelf = self else { return }
if let error = error {
self.popAlert(title: "Error occured", message: error.localizedDescription, alertTitle: "OK") { (action) in
self.emailTextField.text = ""
self.passwordTextField.text = ""
}
print(error.localizedDescription)
} else {
if let user = Auth.auth().currentUser {
self.uid = user.uid
self.performSegue(withIdentifier: Constant.Segue.loginSegue, sender: self)
print("login success!")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment