簡體   English   中英

在 firebase 中更新密碼時出現“TypeError: user.getIdToken is not a function”

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

當我運行 function 更新密碼時,我收到錯誤“TypeError:user.getIdToken 不是一個函數”,它來自 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 將用戶作為第一個參數,而不是用戶的 email。嘗試重構代碼,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM