如何知道电子邮件是否已在firebase身份验证javascript中注册?
我正在为用户进行电子邮件更新,但首先我需要知道该电子邮件之前是否已在firebase身份验证中注册 通过这种方式,我更新了电子邮件:如何知道电子邮件是否已在firebase身份验证javascript中注册?,javascript,firebase,firebase-authentication,Javascript,Firebase,Firebase Authentication,我正在为用户进行电子邮件更新,但首先我需要知道该电子邮件之前是否已在firebase身份验证中注册 通过这种方式,我更新了电子邮件: if(administrador.correo != vm.editedItem.correo){ console.log("ESTA ACTUALIZANDO CORREO"); console.log(vm.editedItem); firebase.auth().signInWithEmailAndPassword
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
});
})
}
按照此链接了解更多信息如果发生错误,请检查已在使用的错误代码auth/email
admin.auth().getUserByEmail()
。构建云函数并从应用程序调用函数