I am new to Firebase and use the email / password login method. I have a method that works fine, however in my registration form I have additional fields that I want to enter into the database. As far as I understand from the registration method by email / password, any additional fields should be stored separately from how authentication by email / password is stored during user registration.
I created a subsection in my databases to store additional user data called users. this is how it looks in firebase:

Here is the function I call (in React) to create a new user:
signUp(e) {
e.preventDefault();
var firstName = $('.signup-first-name').val();
var lastName = $('.signup-last-name').val();
var userName = $('.signup-user-name').val();
var password = $('.signup-user-password').val();
var email = $('.signup-email').val();
var auth = firebase.auth();
const promise = auth.createUserWithEmailAndPassword(email,password).then(function(user) {
var user = firebase.auth().currentUser;
user.updateProfile({
displayName: userName,
}).then(function() {
var ref = new firebase("https://music-app-7a4d3.firebaseio.com");
ref.onAuth(function(authData) {
ref.child("users").child(authData.uid).set({
firstName: firstName,
lastName: lastName
})
})
}, function(error) {
});
}, function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == 'auth/weak-password') {
alert('The password is too weak.');
} else {
console.error(error);
}
});
promise.catch(e => console.log(e.message));
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser) {
console.log(firebaseUser)
} else {
console.log("not logged in")
}
});
}
Another example that I found here followed:
Firebase
, . , !