Действуйте следующим образом:
this.app.auth().createUserWithEmailAndPassword(userForm.value.email, userForm.value.password)
.then(res => {
console.log('2 form data:', userForm.value);
var user = firebase.auth().currentUser;
console.log(user.email);
console.log(user.uid);
return this._firebase.app.database().ref('users').push({
email: user.email,
uid: user.uid
})
})
.catch(err => {
console.log('Something went wrong:', err.message);
});
Это нормально, что вы не получаете параметры, переданные функции в then. Асинхронная функция createUserWithEmailAndPassword
"возвращает firebase.Promise
, содержащую ненулевое значение firebase.auth.UserCredential
", см. https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword
Таким образом, вы должны получить текущего пользователя в функции then с firebase.auth().currentUser;
РЕДАКТИРОВАТЬ после вашего комментария (edit2: который был удален: -))
Сделайте такую функцию и вызовите ее с данными userForm:
function pushUser(userForm.value) {
//create a JavaScript object holding the values you want to push to Firebase
const objectToPush = {
email: userForm.value.email,
uid: userForm.value.uid,
address: userForm.value.address,
.....
};
return this.app.auth().createUserWithEmailAndPassword(userForm.value.email, userForm.value.password)
.then(res => {
//var user = firebase.auth().currentUser; <- you don't need that anymore
//since you have the values in the object
return this._firebase.app.database().ref('users').push(objectToPush);
})
.catch(err => {
console.log('Something went wrong:', err.message);
});
}
PS: позаботьтесь о том, чтобы this
по-прежнему ссылался на то, что вы хотите.