AngularFire2 How to CreateUser ( name, surname, email, password ) AngularFire2 How to CreateUser ( name, surname, email, password ) database database

AngularFire2 How to CreateUser ( name, surname, email, password )


'this.af.auth.createUser' only accepts an email and password. Also, you cannot have a custom property (name or surname) on Firebase's built in user profile.

The only available properties are:

  • displayName
  • email
  • photoURL
  • providerId
  • uid

So you could definitely store it in 'displayName' if you wanted, otherwise you're going to have to use the Firebase Realtime Database to store additional user data. I believe to set 'displayName' you'll have to have the person signed in.

To use displayName you can do the following (once you have the signed in user):

user.updateProfile({  displayName: "Name here"}).then(() => {  // Update successful}

To use the Firebase Realtime Database:

registerUser(formData) {    if(formData.valid) {        this.af.auth.createUser({            // Create user            email: formData.value.email,            password: formData.value.password        }).then((user) => {            // User created now create the database user            return this.af.database.object(`/users/${user.uid}`).update({                name: formData.value.name,                surname: formData.value.surname            });        }).then(() => {            // Success            this.routing.navigateByUrl('/login');        }).catch((error) => {            // Error            console.log(error);        });    }}

(Not had chance to test the above code).