例如:
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// [START_EXCLUDE]
if (errorCode == 'auth/weak-password') {
alert('The password is too weak.');
exit;
} else {
alert(errorMessage);
exit;
}
console.log(error);
// [END_EXCLUDE]
});
这仅创建用户并验证错误,但不指示用户创建是否成功,因为我需要采取操作,例如将用户名保存在我的数据库中(如果用户创建成功)或重定向,如果用户创建成功。
如果用户 createUserWithEmailAndPassword 成功,我该如何采取行动?
最佳答案
使用 .then()
代替:
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(result){
// update your database
}, function(error){
// handle the error
});
关于javascript - 我如何知道使用电子邮件和密码创建用户是否成功?并采取行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48433974/