javascript - 如何知道电子邮件是否已经在firebase身份验证中注册,javascript?
问题描述
我正在为用户进行电子邮件更新,但首先我需要知道该电子邮件之前是否已在 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
});
})
}
点击此链接获取更多更新电子邮件
推荐阅读
- java - java.lang.IllegalAccessException:试图从非可视上下文访问可视服务 WindowManager
- android-fragments - Jetpack 组成没有片段的导航架构?
- python - 使用 .csv 文件中的数据创建字典
- julia - 交互张量的积分
- java - 为什么找不到 Spring 自定义登录表单但其他页面工作正常?
- python - Windows Azure 管道中的 python setup.py build_ext
- vue.js - Buefy:如何在单独注册组件时设置图标包
- python - 无法在 Python 中使用 CSV 打印数据
- css - SVG CSS 动画平滑过渡和原点
- javascript - 我想改进这个通过 ''value=" 过滤 CheckBoxes 列表的 JavaScript 代码