0
votes

I'm using firebase with angular4 with the angularfire2 library. After signing up user with email and password I can see the user has been registered in the database in firebase. However I cannot add extra fields like name, address, etc. I thought of creating a ('/users') list then use the user's Uid to store user profile information. But the document says I can assign "name" and "profile picture". If that's the case I cannot add any field to the users database from authentication.

2
Please include a code sample showing what you've tried and any errors you saw. Have you read the documentation on user profiles? firebase.google.com/docs/auth/web/…Travis Christian
@Travis Christian thanks for your reply. yes i was following firebase documentation: firebase.google.com/docs/reference/js/firebase.UserInfo. i can see the signed up users in authetication section. what i am wondering is firebase docs shows that i can add user name and upload a picture. but it seems like there are no fields of name and number in the authentication sectionManas

2 Answers

1
votes

As you mention, by the firebase documentation, you can do it by using angularfire2 like this:

  this.af.auth.createUser({
    email: <UserEmail>,
    password: <UserPass>
  }).then(
    (success) => {
    success.auth.updateProfile({
        displayName: <UserName>,
        photoURL: <UserPhotoURLString>
      })
      .then(res => console.log("profile updated"))
      .catch(err => console.log(err));
  }).catch(
    (err) => {
    console.log(err);
  })

as you can see in the code attach above, after you use the built-in method of af.auth.createUser you receive as promise an User object, and after that you can use another built-in method success.auth.updateProfile to update the User Profile area in the firebase authetication section. This code worked for me perfectly, so just adjust this to your code and that it :) enjoy.

0
votes

AngularFire2 has a new version of the update. You can try out this code for the new angularfire version.

this.afAuth.auth.currentUser.updateProfile({
          displayName: 'your profile name',
          photoURL: 'your pic url'
        }).then(() => {
          console.log('DisplayName updated')
        }).catch(err => console.log(err))

You can use this code for update user date when you logged in.