Putte
Putte

Reputation: 536

Segue is not being performed

I've created a method for auto login via Firebase but somehow my segue is not being performed..

I've this code and in my viewDidLoad I'm calling the method (ofc)

override func viewDidLoad() {
super.viewDidLoad()

  //Login user automatically
  autoLogin()
}

func autoLogin(){
    if Auth.auth().currentUser?.email != nil{

        print("not nil") //for test
        self.performSegue(withIdentifier: "toRootVc", sender: self)
        print("not nil1") //for test
    }
    else{
        print("nil") //for test
    }
}

The app prints both "not nil" and "not nil1" but it still does not performing the segue.

I also have a login button which works.

func handleLogin(){
    Auth.auth().signIn(withEmail: email.text!, password: password.text!) { (result, err) in
        if let err = err{
            print("Error logging in:", err.localizedDescription)
        }
        else{
            self.databaseHandler.retrieveData(email: self.email.text!){
                self.performSegue(withIdentifier: "toRootVc", sender: self)
            }
        }
    }
}

But the autoLogin doesn't actually performing the segue. (Ignores the step)

Any input would be much appreciated.

Upvotes: 0

Views: 66

Answers (2)

Shehata Gamal
Shehata Gamal

Reputation: 100503

Segues won't work inside viewDidLoad as it's too early try in viewWillAppear or better do this check before presenting that vc say inside didFinishLaunchingWithOptions of AppDelegate

Upvotes: 1

Sore
Sore

Reputation: 186

have you tried to put this autoLogin() on viewDidAppear()

Upvotes: 0

Related Questions