Firebase creates a user by email, password, display name and photo URL

According to the Firebase site, I use this code to create a new user:

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

How to add the display name and URL of a photo in Auth when creating a new user?

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

+9
source share
5 answers

You can update your profile using the FIRUserProfileChangeRequest class .. check this document

 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. } } } 
+18
source

To change / add display name:

user!.createProfileChangeRequest().displayName = "Your name"

To change / add photosURL

user!.createProfileChangeRequest().photoURL = URL(string: "image url")

+1
source

You can simply solve your problem as follows.

1) Create a user using the following statement.

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

2) The success of the above operator. authenticate this user as shown below.

  self.rootRef.authUser(email, password) // USER_ID = Here you get user_ID 

3) The success of the above function sets the user with a username and profile picture as follows.

  usersRef.updateChildValues(dict, withCompletionBlock: 

-Register userRef with your userDetails / USER_ID

Perhaps you will work. I have code, but I work for an older version of firebase, so I do not work for you, otherwise I have a share with you.

0
source

I think you mean adding the display name and URL of the photo to the Firebase database after Auth. This is pretty much what I do with the same registration.

  if let email = emailField.text where email != "", let pwd = passwordField.text where pwd != ""{ FIRAuth.auth()?.createUserWithEmail(email, password: pwd, completion: { (user, error) in if error != nil { print("DEVELOPER: Unable to authenticate with Firebase using email") }else { print("DEVELOPER: Successfully authenticated with Firebase using email") if let user = user { let userData = ["provider": user.providerID, "userName": "\(user.displayName)", "profileImg": "\(user.photoURL)"] self.completeMySignIn(user.uid, userData: userData) } } }) } else { // Email and Password where not filled in } } 

Now adding the image of your profile and user to the database here

 func completeMySignIn(id: String, userData: Dictionary<String, String>){ {YourFirebaseUserURL}.updateChildValues(userData) } 
0
source

I think this should solve this for you, let me know if you need anything else. or have additional questions on this.

  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) } } } 
0
source

All Articles