I have implemented a Firebase Google login into my Swift App. I want to check in the beginning if its already a logged in user or not. I do this like that:
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}
Now my problem is: It works how I want, but its pretty slow. I can still get a quick look at the login screen, before my main page gets presented.
Now if I want to add the currentUser check to the viewDidLoad, the App doesnt check if the User has already logged in before.
Any recommendations?
Do it on main thread
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}