Search code examples
angularfirebasefirebase-authenticationangularfire2

how to add user's extra profile information apart from email and password in firebase?


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.


Solution

  • 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.