Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 215
Manatee Avatar asked May 27 '18 15:05

Manatee


2 Answers

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

self.name = user.user.displayName
like image 153
Abhishek Avatar answered Oct 18 '22 03:10

Abhishek


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

like image 42
Soropromo Avatar answered Oct 18 '22 03:10

Soropromo