Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. @IBAction func didTapSignIn(sender: AnyObject) {
  2. let email = emailField.text
  3. let password = passwordField.text
  4. FIRAuth.auth()?.signInWithEmail(email!, password: password!) { (user, error) in
  5. if let error = error {
  6. print(error.localizedDescription)
  7. return
  8. }
  9. self.signedIn(user!)
  10. }
  11. }
  12.  
  13. func signedIn(user: FIRUser?) {
  14. AppState.sharedInstance.displayName = user?.displayName ?? user?.email
  15. AppState.sharedInstance.signedIn = true
  16. NSNotificationCenter.defaultCenter().postNotificationName(Constants.NotificationKeys.SignedIn, object: nil, userInfo: nil)
  17. performSegueWithIdentifier(Constants.Segues.SignInToHome, sender: nil)
  18. }
  19.  
  20. override func viewDidAppear(animated: Bool) {
  21. super.viewDidAppear(true)
  22. //Synchronously gets the cached current user, or null if there is none.
  23. if let user = FirebaseConfigManager.sharedInstance.currentUser {
  24. self.signedIn(user)
  25. }
  26. }
  27.  
  28. @IBAction func didTapSignOut(sender: UIBarButtonItem) {
  29. print("sign out button tapped")
  30. let firebaseAuth = FIRAuth.auth()
  31. do {
  32. try firebaseAuth?.signOut()
  33. AppState.sharedInstance.signedIn = false
  34. dismissViewControllerAnimated(true, completion: nil)
  35. } catch let signOutError as NSError {
  36. print ("Error signing out: (signOutError)")
  37. } catch {
  38. print("Unknown error.")
  39. }
  40. }
  41.  
  42. po FIRAuth.auth()?.currentUser
  43. ▿ Optional<FIRUser>
  44. - Some : <FIRUser: 0x7fde43540f50>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement