Search code examples
iosswiftxcodeapplet

performSegue not working FireBase while checking the user is authenticated Swift 3/4


I just finish a tutorial video of letsbuildthatapp about firebase mixed with social login.

I currently trying to perform a segue if the user is already authenticated.

I print something in my if and just after I performSegue with a segue who I know work because I'm using it for a test.

there is my code

func verifDejaConnecter() {
    if Auth.auth().currentUser?.uid != nil {
        performSegue(withIdentifier: "segueAccueilToPres", sender: nil)
        print("test")
    } else {
        return
    }
}

mySegue is created and works but nothing append here.

In the console I can see the test resulting from the print in the if ... but nothing is mooving


Solution

  • Try this:

    func verifDejaConnecter() {
      if Auth.auth().currentUser?.uid != nil {
        DispatchQueue.main.async {
          self.performSegue(withIdentifier: "segueAccueilToPres", sender: self)
            print("test")
        }
      } else {
        return
      }
    }