Alex Alex - 4 months ago 277
Swift Question

Firebase create user with email, password, display name and photo url

According to Firebase site, I am using this code to create a new user:

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {});


How can I add display name and photo url to Auth when creating the new user?

This link shows the supported user data returned from an identity provider in Auth.

Answer

You can update your profile with FIRUserProfileChangeRequest class .. check this Doc.

let user = FIRAuth.auth()?.currentUser
   if let user = user {
      let changeRequest = user.profileChangeRequest()

      changeRequest.displayName = "Jane Q. User"
      changeRequest.photoURL =
          NSURL(string: "https://example.com/jane-q-user/profile.jpg")
      changeRequest.commitChangesWithCompletion { error in
        if let error = error {
          // An error happened.
        } else {
          // Profile updated.
        }
      }
    }