Greetings StackOverflow!
I'm really new to Swift development, so don't go all crazy on me please :3
I've created a login page for my mobile app (Firebase Email + Password)
I've implemented an "auto login" function - so when a user logs in for the first time, the user stays logged after closing the app & opening it.
The problem is that every time a user opens the app, there is a slight delay between viewDidLoad and viewDidAppear -> resulting in that every time the app opens, you can see the login screen for about 0.4 sec until it automatically sings the user in.
Once the user logs in the user are segued (no animation) to my UITabBarController.
I've provided the code for my LoginViewController.
LoginViewController is my first Controller the app loads in.
Best regards
class LoginViewController: UIViewController {
@IBOutlet weak var loginEmail: UITextField!
@IBOutlet weak var loginPassword: UITextField!
@IBOutlet weak var loginBorder: UIButton!
let userDefault = UserDefaults.standard
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
if userDefault.bool(forKey: "usersignedin") {
performSegue(withIdentifier: "login", sender: self)
}
//Border color button//
loginBorder.layer.borderColor = UIColor.white.cgColor
//Border color button//
//Hide Keyboard Use
self.hideKeyboardWhenTappedAround()
//Hide Keyboard Use
//start padding function for login
addPaddingAndBorder(to: loginEmail)
addPaddingAndBorder(to: loginPassword)
//start padding function for login
}
@IBAction func loginButton(_ sender: UIButton) {
Auth.auth().signIn(withEmail: loginEmail.text!, password: loginPassword.text!) { (user, error) in
if user != nil {
self.userDefault.set(true, forKey: "usersignedin")
self.userDefault.synchronize()
self.performSegue(withIdentifier: "login", sender: self)
} else {
let alert = UIAlertController(title: "Invalid Email or Password", message: nil, preferredStyle: .alert)
let okButton = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okButton)
self.present(alert, animated: true, completion: nil)
}
}
}
}