Reputation: 467
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.
Upvotes: 1
Views: 925
Reputation: 2996
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.
Upvotes: 4