Guest User

Untitled

a guest
Feb 2nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Auth.auth().signIn(withEmail: emailAddress, password: password) { (user, error) in
  2. // If Successful, pull firstName/lastName
  3. let ref: DatabaseReference!
  4. ref = Database.database().reference().child("users").child(emailAddress)
  5.  
  6. ref!.observe(DataEventType.value, with: { (snapshot) in
  7. // Get user value
  8. let postDict = snapshot.value as? NSDictionary ?? [:]
  9. let firstName = postDict["firstName"] as? String ?? ""
  10. let lastName = postDict["lastName"] as? String ?? ""
  11. let showroom = postDict["showroom"] as! NSDictionary
  12. let showroomReference = showroom["showroomID"] as? String ?? ""
  13.  
  14. if showroomReference == "" {
  15. completionHandler(.failure(Error.unknownShowroom))
  16. }
  17.  
  18. let remoteUser = try User(record: postDict, context: DatabaseManager.shared.persistentContainer.newBackgroundContext())
  19.  
  20. self.fetchShowroom(forIdentifier: showroomReference) { (result) in
  21. do
  22. {
  23. let showroom = try result.value()
  24. remoteUser.showroom = showroom
  25. remoteUser.brands = showroom.brands
  26.  
  27. completionHandler(.success(remoteUser))
  28. }
  29. catch
  30. {
  31. completionHandler(.failure(error))
  32. }
  33. }
  34. })
  35. }
Add Comment
Please, Sign In to add comment