在 Firebase 中更新密码时获取"TypeError: user.getIdToken is not a function"



当我运行函数updatePassword时,我得到错误"TypeError:user.getIdToken不是函数";,它来自firebasesdk中的一个文件。

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()函数将User作为第一个参数,而不是用户的电子邮件。尝试重构如下所示的代码:

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

相关内容

最新更新