Firebase create user with email, password, display name and photo url
I think this should solve it for you, let me know if you need anything else. or have any further questions on this matter.
func handleSignUp() {
guard let userName = userNameTF.text else { return }
guard let email = emailTF.text else { return }
guard let password = passwordTF.text else { return }
guard let image = profileImage.image else { return }
continueButton.setBackgroundImage(#imageLiteral(resourceName: "inactiveButtonBG"), for: .normal)
activityIndicator.startAnimating()
Auth.auth().createUser(withEmail: email, password: password) { user, error in
if error == nil && user != nil {
print("User created!")
self.uploadProfileImage(image: image) { url in
if url != nil {
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = userName
changeRequest?.photoURL = url
changeRequest?.commitChanges { error in
if error == nil {
self.saveProfile(username: userName, profileImageURL: url!) { success in
if success {
print("Success upload of profile image")
self.dismiss(animated: true, completion: nil)
}
}
self.dismiss(animated: true, completion: nil)
} else {
guard let message = error?.localizedDescription else { return }
self.userAlert(message: message)
}
}
} else {
self.userAlert(message: "Unable to load profile image to Firebase Storage.")
}
}
self.dismiss(animated: true, completion: nil)
} else {
guard let message = error?.localizedDescription else { return }
self.userAlert(message: message)
}
}
}
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.
}
}
}