这是我用来将用户注册到Firebase数据库的功能。一次又一次,else
部分正在执行(即未创建用户)。我可以有替代代码吗?
function registerUser(email, password){
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
var user = firebase.auth().currentUser;
if (user) {
// User is created if will be automatically signed in
console.log('created and signed in');
} else {
// No user created hence not signed in.
console.log("failed");
}
});
}
答案 0 :(得分:0)
firebase.auth().createUserWithEmailAndPassword('email@gmail.com', 'password')
.then(function (firebaseUser) {
console.log(firebaseUser.user);
})
.catch(function (error) {
console.log(error);
});