Getting "TypeError: user.getIdToken is not a function" when updating password in firebase

Getting "TypeError: user.getIdToken is not a function" when updating password in firebase

当我 运行 函数 updatePassword 出现错误“TypeError: user.getIdToken is not a function”,它来自 firebase sdk 中的一个文件。

async changePassword(state, payload) {
      const user = auth.currentUser
      let cred = EmailAuthProvider.credential(
        payload.email,
        payload.oldPassword
      )

      reauthenticateWithCredential(user, cred)
        .then(() => {
          // User re-authenticated.
          console.log(payload.newPassword)
          updatePassword(payload.email, payload.newPassword)
            .then(() => {
              // Update successful.
              console.log('Succeed')
            })
            .catch((error) => {
              console.log('Failed', error)
              // An error ocurred
              // ...
            })
        })
        .catch((error) => {
          // An error ocurred
          // ...
          console.log(error)
        })
    },

updatePassword() function takes User 作为第一个参数而不是用户的电子邮件。尝试重构代码,如下所示:

reauthenticateWithCredential(user, cred).then(({ user }) => {
  // Pass user here and not payload.email 
  updatePassword(user, payload.newPassword).then(() => {
    console.log('Succeed')
  }) 
})