Guest User

Untitled

a guest
Feb 27th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: {
  2. (user, error) in
  3.  
  4. // user's auth credentials are now created but user can still be nil
  5.  
  6. Auth.auth().signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!, completion: {
  7. (user, error) in
  8.  
  9. // user's auth credentials are now accessed but user can still be nil
  10.  
  11. class FirebaseSingleton{
  12.  
  13. static let sharedInstance = FirebaseSingleton()
  14.  
  15. var dbRef: DatabaseReference? = Database.database().reference()
  16. var storageDbRef: StorageReference? = Storage.storage().reference(forURL: "gs://blablabla.appspot.com")
  17. var currentUser: User? = Auth.auth().currentUser
  18. var currentUserID: String? = Auth.auth().currentUser?.uid
  19. var currentUserEmail: String? = Auth.auth().currentUser?.email
  20. var currentUserPhotoUrl: URL? = Auth.auth().currentUser?.photoURL
  21. var currentUserDisplayName: String? = Auth.auth().currentUser?.displayName
  22. }
  23.  
  24. Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: {
  25. (user, error) in
  26.  
  27. if error != nil { return }
  28.  
  29. if let user = user{
  30.  
  31. let sharedInstance = FirebaseSingleton.sharedInstance
  32. sharedInstance.currentUser = user
  33. sharedInstance.currentUserID = user.uid
  34. sharedInstance.currentUserEmail = user.email // at this point is it possible for this to be nil?
  35. sharedInstance.currentUserPhotoUrl = user.photoURL
  36. sharedInstance.currentUserDisplayName = user.displayName
  37. }else{
  38. return
  39. }
  40.  
  41. // is this guard statement necessary?
  42. guard let email = user.uid else { return }
  43. })
  44.  
  45. Auth.auth().signIn(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: {
  46. (user, error) in
  47.  
  48. if error != nil { return }
  49.  
  50. if let user = user{
  51.  
  52. let sharedInstance = FirebaseSingleton.sharedInstance
  53. sharedInstance.currentUser = user
  54. sharedInstance.currentUserID = user.uid
  55. sharedInstance.currentUserEmail = user.email // at this point is it possible for this to be nil?
  56. sharedInstance.currentUserPhotoUrl = user.photoURL
  57. sharedInstance.currentUserDisplayName = user.displayName
  58. }else{
  59. return
  60. }
  61.  
  62. // is this guard statements necessary?
  63. guard let email = user.uid else { return }
  64. })
Add Comment
Please, Sign In to add comment