Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Auth.auth().signIn(withEmail: emailAddress, password: password) { (user, error) in
- // If Successful, pull firstName/lastName
- let ref: DatabaseReference!
- ref = Database.database().reference().child("users").child(emailAddress)
- ref!.observe(DataEventType.value, with: { (snapshot) in
- // Get user value
- let postDict = snapshot.value as? NSDictionary ?? [:]
- let firstName = postDict["firstName"] as? String ?? ""
- let lastName = postDict["lastName"] as? String ?? ""
- let showroom = postDict["showroom"] as! NSDictionary
- let showroomReference = showroom["showroomID"] as? String ?? ""
- if showroomReference == "" {
- completionHandler(.failure(Error.unknownShowroom))
- }
- let remoteUser = try User(record: postDict, context: DatabaseManager.shared.persistentContainer.newBackgroundContext())
- self.fetchShowroom(forIdentifier: showroomReference) { (result) in
- do
- {
- let showroom = try result.value()
- remoteUser.showroom = showroom
- remoteUser.brands = showroom.brands
- completionHandler(.success(remoteUser))
- }
- catch
- {
- completionHandler(.failure(error))
- }
- }
- })
- }
Add Comment
Please, Sign In to add comment