我正在为用户进行电子邮件更新,但首先我需要知道该电子邮件之前是否已在 Firebase 身份验证中注册。
通过这种方式我更新了电子邮件:
if(administrador.correo != vm.editedItem.correo){
console.log("ESTA ACTUALIZANDO CORREO");
console.log(vm.editedItem);
firebase.auth().signInWithEmailAndPassword(vm.editedItem.correo, vm.editedItem.contrasenia)
.then(function(userCredential) {
console.log("USER CREDENTIAL");
console.log(userCredential);
userCredential.user.updateEmail(vm.editedItem.correo)
.then(function() {
console.log("email update");
// Update successful.
}).catch(function(error) {
console.log("ERROR");
console.log(error);
// An error happened.
});
})
}
但是在我更新电子邮件之前,我必须验证它是否已经存在,如果电子邮件存在,因为不允许更新邮件,如果电子邮件不存在,因此我更新电子邮件。
首先非常感谢您。
最佳答案
检查下面的代码。我认为您正在尝试更改您登录时使用的同一电子邮件。我做了一些细微的更改和评论。
if (administrador.correo != vm.editedItem.correo) {
console.log("ESTA ACTUALIZANDO CORREO");
console.log(vm.editedItem);
firebase.auth().signInWithEmailAndPassword(vm.currentItem.correo, vm.editedItem.contrasenia) // sign in with current email and password
.then(function (userCredential) {
console.log("USER CREDENTIAL");
console.log(userCredential);
userCredential.user.updateEmail(vm.editedItem.correo) // update new email
.then(function () {
console.log("email update");
// Update successful.
}).catch(function (error) {
console.log("ERROR");
console.log(error);
// An error happened.
// if updated user email already exists, it returns error code: auth/email-already-in-use
});
})
}
点击此链接了解更多信息updateEmail
关于javascript - 如何知道电子邮件是否已经在firebase身份验证中注册,javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55720389/