【问题标题】:Firebase - email is not definedFirebase - 未定义电子邮件
【发布时间】:2022-07-20 17:33:58
【问题描述】:

我正在尝试构建一个允许用户更改密码的功能。问题是当我获取当前用户的数据时,它显示电子邮件为空。

一切都在 Firebase 上运行,用户在 Firebase 身份验证系统中创建。

这是我的代码的一部分

reauthenticate = (currentPassword) => {
    var user = firebase.auth().currentuser;
    var cred = firebase.auth.EmailAuthProvider.credential(user.email, currentPassword);
    user.reauthenticateWithCredential(cred);
}

reauthenticate(currentPassword).then(() => {
    var user = firebase.auth().currentuser;
    user.updatePassword(newPassword).then(() => {
        alert("Password changed");
        window.location.replace("./index.html");
    }).catch((error) => {
        console.log(error);
    })
});

控制台显示的是Uncaught TypeError: Cannot read properties of undefined (reading 'email') at reauthenticate (password.js:15:64) at changePassword (password.js:27:9)

【问题讨论】:

    标签: javascript node.js reactjs firebase firebase-realtime-database


    【解决方案1】:

    它的当前用户不是当前用户。大写U。

    const user = firebase.auth().currentUser;
    

    【讨论】:

      猜你喜欢
      • 2019-05-28
      • 2020-01-27
      • 2020-04-24
      • 2021-05-26
      • 2012-11-26
      • 2018-10-09
      • 1970-01-01
      • 2023-03-04
      相关资源
      最近更新 更多