1

I am using Firebase with Angular 2 to create new users. I would like to extend this by adding additional data for each newly created user. In this example, I would like to have every newly created user start with an assigned property of net worth = 5000. So my schema would look something like:

email | ''
password | ''
net worth | '5000'

Having gone through the Firebase docs, I have found the save data feature. However, I am unsure how to merge the set feature with my username and password authentication script.

Below is the basic signup script.

signup(){
     firebase.auth().createUserWithEmailAndPassword('[email protected]', 'ucantcme')
     .catch(function(error){
     console.log(error);
});}

I would like to know how to implement the set feature with this signup so I can add default data for users.

1 Answer 1

4

You can't save 'net_worth' in the auth area. For that you need a seperate table in the database . For example 'users'. Check the below code.

After user creation you get UID. Using that UID store the related data into the database.

firebase.auth().createUserWithEmailAndPassword('[email protected]', 'ucantcme')
   .then(function(response) {
      console.log(response.uid); // Created user UID

      var updates = {};
      updates['/users/' + response.uid] = { net_worth : 5000 };
      firebase.database().ref().update(updates);
});

Here 'users' is a new table.

Sign up to request clarification or add additional context in comments.

1 Comment

Property 'uid' does not exist on type 'void | UserCredential'. Property 'uid' does not exist on type 'void'.ts(2339)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.