Answer the question
In order to leave comments, you need to log in
How to display errors and hide controller in swift?
Good afternoon, a question for professionals, please help. I decided to write an application, it has a storyboard with authorization where everything is folded for me, authorization, registration and recovery.
All authorization goes through Firebase.
In general, the problem itself
. I have two fields: name and password, as well as the login button - the action I have is attached to this code
@IBAction func checkLogin(_ sender: UIButton) {
let email = userEmail.text!
let passwd = userPassword.text!
if email == "" || passwd == "" || !email.isValidEMail {
userEmail.shake()
userPassword.shake()
return
}
Auth.auth().signIn(withEmail: email, password: passwd) { (user, error) in
if error != nil {
let alert = UIAlertController(title: "Ошибка!", message: (error?.localizedDescription)!, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
} else {
// TODO: Save user data to Locksmith
if let user = user {
do {
try Locksmith.saveData(data: ["user_uid": user.uid], forUserAccount: "myUserAccount")
} catch (let err) {
print(err)
}
}
let alert = UIAlertController(title: "Вы авторизированны", message: "вы зашли как: \(user?.uid)", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
let userUID = Auth.auth().currentUser?.uid
print("\(userUID)")
if userUID != nil {
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question