Skip to content

Instantly share code, notes, and snippets.

@zontan
Created September 23, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zontan/e525638c8883ff5bfbb1666c8e10a361 to your computer and use it in GitHub Desktop.
Save zontan/e525638c8883ff5bfbb1666c8e10a361 to your computer and use it in GitHub Desktop.
var handle: AuthStateDidChangeListenerHandle?
override func viewWillAppear(_ animated: Bool) {
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
if user != nil {
self.nameTextField.text = user?.displayName
} else {
self.navigationController?.popToRootViewController(animated: true)
}
}
}
override func viewWillDisappear(_ animated: Bool) {
if let handle = handle {
Auth.auth().removeStateDidChangeListener(handle)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment