Skip to content

Instantly share code, notes, and snippets.

@atanasovdejan
Created August 4, 2018 11:13
Show Gist options
  • Save atanasovdejan/ffe4396ac9f715447ae3b6de9aec821d to your computer and use it in GitHub Desktop.
Save atanasovdejan/ffe4396ac9f715447ae3b6de9aec821d to your computer and use it in GitHub Desktop.
Update Profile Picture and Display Name in Firebase User
func updateProfileInfo(withImage image: Data? = nil, name: String? = nil, _ callback: ((Error?) -> ())? = nil){
guard let user = Auth.auth().currentUser else {
callback?(nil)
return
}
if let image = image{
let profileImgReference = Storage.storage().reference().child("profile_pictures").child("\(user.uid).png")
_ = profileImgReference.putData(image, metadata: nil) { (metadata, error) in
if let error = error {
callback?(error)
} else {
profileImgReference.downloadURL(completion: { (url, error) in
if let url = url{
self.createProfileChangeRequest(photoUrl: url, name: name, { (error) in
callback?(error)
})
}else{
callback?(error)
}
})
}
}
}else if let name = name{
self.createProfileChangeRequest(name: name, { (error) in
callback?(error)
})
}else{
callback?(nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment