Manatee
Manatee

Reputation: 51

Firebase Error Value of type 'AuthDataResult' has no member 'displayName'

I'm following along Rob Percival's iOS developer course and I am currently stuck at the "Uber clone" project. Following is an extract of the problematic code. The line of code in which the error occurs is:

if user?.displayName == "Lehrer" {

which is found after the comment //LOG IN

@IBAction func topTapped(_ sender: Any) {
    if emailTextField.text == "" || passwordTextField.text == "" {
        displayAlert(title: "Achtung", message: "Du musst sowohl eine Email-Adresse als auch Passwort eingeben!")
    } else {
        if let email = emailTextField.text {
            if let password = passwordTextField.text {
                if signUpMode {
                    // SIGN UP
                    Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
                        if error != nil {
                            self.displayAlert(title: "Error", message: error!.localizedDescription)
                        } else {

                            if self.benutzerLehrerSwitch.isOn {
                                //Lehrer
                                let req = Auth.auth().currentUser?.createProfileChangeRequest()
                                req?.displayName = "Lehrer"
                                req?.commitChanges(completion: nil)
                                self.performSegue(withIdentifier: "lehrerSegue", sender: nil)
                            } else {
                                // RIDER
                                let req = Auth.auth().currentUser?.createProfileChangeRequest()
                                req?.displayName = "Benutzer"
                                req?.commitChanges(completion: nil)
                                self.performSegue(withIdentifier: "benutzerSegue", sender: nil)
                            }
                        }
                    })
                } else {
                    // LOG IN
                    Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
                        if error != nil {
                            self.displayAlert(title: "Error", message: error!.localizedDescription)
                        } else {
                            if user?.displayName == "Lehrer" {
                                // BENUTZER
                                self.performSegue(withIdentifier: "benutzerSegue", sender: nil)
                            } else {
                                // LEHRER
                                self.performSegue(withIdentifier: "lehrerSegue", sender: nil)
                            }
                        }
                    })
                }
            }
        }
    }
}

Basically, I allow users to sign up as one of two different types of roles ("Lehrer" or "Benutzer") and depending on which of those they choose, they should see different screens after logging in. I use Firebase for the backend of this code and signing up User's accounts works fine if I delete the faulty code. Does anyone have any ideas?

You can see the exact look in this screenshot:

Screenshot of the error

Upvotes: 5

Views: 1400

Answers (2)

Abhishek
Abhishek

Reputation: 1674

Google has updated the methods after Firebase 5+ update try this

self.name = user.user.displayName

Upvotes: 6

Soropromo
Soropromo

Reputation: 1282

put user?.user.displayName instead of user?.displayName

Upvotes: 2

Related Questions