Guest User

Untitled

a guest
Nov 1st, 2018
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. Create user
  2. -------------
  3. Auth.auth().createUser(withEmail: "user@email.com", password: "PASSWORD******") { (user, error) in
  4. if let error = error {
  5. print(error.localizedDescription)
  6. }
  7. else if let user = user {
  8. print("Sign Up Successfully. \(user.uid)")
  9. }
  10. }
  11. ---------------------
  12. Login
  13. ---------------------
  14. Auth.auth().signIn(withEmail: "user@email.com", password: "PASSWORD******") { (user, error) in
  15. if let error = error {
  16. print(error.localizedDescription)
  17. }
  18. else if let user = user {
  19. print(user.uid)
  20. }
  21. }
  22. ------------------------
  23. SignOut
  24. ------------------------
  25.  
  26. if Auth.auth().currentUser != nil {
  27. do {
  28. try Auth.auth().signOut()
  29. }
  30. catch {
  31. }
  32. }
  33. -------------------------
  34. show New VC if Succss Login or Create User
  35. -------------------------
  36. 1- add New Id to New VC Storybode `ID "Home"
  37. 2- add the Code
  38. print("Sign Up Successfully")
  39. let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
  40. self.present(viewController, animated: true, completion: nil)
  41.  
  42. -------------------------
  43. 3- Code To Remember
  44.  
  45. -----------
  46.  
  47. import UIKit
  48. import Firebase
  49. import FirebaseAuth
  50.  
  51. class ViewController: UIViewController {
  52. @IBOutlet weak var email: UITextField!
  53. @IBOutlet weak var password: UITextField!
  54.  
  55. override func viewDidLoad() {
  56. super.viewDidLoad()
  57.  
  58. }
  59.  
  60. @IBAction func Login(_ sender: Any) {
  61. Auth.auth().createUser(withEmail: email.text!, password: password.text!) { (user, error) in
  62. if let error = error {
  63. print(error.localizedDescription)
  64.  
  65. }
  66. else if let user = user {
  67. print("Sign Up Successfully")
  68. let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
  69. self.present(viewController, animated: true, completion: nil)
  70. }
  71. }
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment