我正在使用firebase.auth()。createUserWithEmailAndPassword,但我也想在注册屏幕中保存其他数据,例如名字和姓氏。
我尝试执行此代码,但它仅使用电子邮件和密码创建用户。它不会在数据库中保存用户的名字和姓氏。
signUpUser = (email, password, firstName, lastName) => {
try {
if (this.state.password.length < 6) {
alert("Please enter atleast 6 characters");
return;
}
firebase.auth().createUserWithEmailAndPassword(email,password)
.then(
firebase.database().ref('users.' + firebase.auth().currentUser.uid + '/').set({
firstName: firstName,
lastName: lastName
})
)
} catch (error) {
console.log(error.toString());
}
}
答案 0 :(得分:0)
export const addProfile = ({firstname, lastname, email}) => new Promise((resolve, reject) => {
var d = new Date();
var userId = firebaseApp.auth().currentUser.uid;
var userProfile = {
created: d,
firstname: firstname,
lastname: lastname,
};
firebaseApp.database().ref(`profiles/${userId}`).set(userProfile)
.then( () => resolve(userProfile) )
.catch( error => reject(error) );
});