Firebase not working in Swift

I use the latest Firebase API (3.2.1) and I use this code to check if the user has been signed:

override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if(self.navigationController != nil){ self.navigationController!.setNavigationBarHidden(true, animated: true) } if(FIRAuth.auth() != nil){ self.performSegueWithIdentifier("loginSuccessSegue", sender: self) } } 

In other words, if an auth object is present, I switch to another controller. On this controller, I have an exit button that does this as follows:

 do{ try FIRAuth.auth()?.signOut() self.performSegueWithIdentifier("logoutSegue", sender: self) }catch{ print("Error while signing out!") } 

I do not get an error in this operation, but when I switched to the login controller, this auth object is present, and I again switched to the controller with data. I also tried checking the current user object in auth and it is present and valid.

Does anyone know how I'm going out right?

+7
swift firebase firebase-authentication
source share
2 answers

try using:

 try! FIRAuth.auth()!.signOut() 

This is the code I have in IBAction and it works fine:

 try! FIRAuth.auth()!.signOut() if let storyboard = self.storyboard { let vc = storyboard.instantiateViewControllerWithIdentifier("firstNavigationController") as! UINavigationController self.presentViewController(vc, animated: false, completion: nil) } 
+21
source share

I would like to add that I had the same problem and am trying to use the different combinations of code that others have suggested.

The problem for me was that when I set my Exit button in the storyboard, I also created a connection by dragging the control from the button onto the login controller, thinking that this is what I wanted to do.

It turned out that my checkout code never ran because Triggered Segue returned to the login controller, so it returned to the login screen and immediately to my second view controller because the user never logged out.

So in the end this worked for me:

 do { try Auth.auth().signOut() self.dismiss(animated: true, completion: nil) } catch let err { print(err) } 

But only after I deleted the segue, I unwittingly created.

0
source share

All Articles