简体   繁体   English

在 firebase 中更新密码时出现“TypeError: user.getIdToken is not a function”

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

When I run the function updatePassword I get the error "TypeError: user.getIdToken is not a function", which comes from a file in the firebase sdk.当我运行 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)
        })
    },

The updatePassword() function takes User as first parameter and not user's email. Try refactoring the code as shown below: 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.

相关问题 user.getIdToken 不是 function - user.getIdToken is not a function Firebase function 尝试写入 firebase 存储“Firebase 存储:用户无权访问”时出错 - Firebase function getting error when trying to write to firebase storage "Firebase Storage: User does not have permission to access" firebase 可以为特定用户提供多少次“currentUser.getIdToken() 和 verifyIdToken()”请求? - How many times can firebase serve, the "currentUser.getIdToken() and verifyIdToken()" requests, for the particular user? Android Studio - 从 GetIdToken 获取 Firebase 令牌 - Android Studio - Get Firebase token from GetIdToken Firebase Auth UI Android,getIdToken() 返回的任务永远不会完成 - Firebase Auth UI Android, task returned by getIdToken() never completes 类型错误:firebase.storage 不是 function - TypeError: firebase.storage is not a function Firebase signinwithemail&password 不是 function - Firebase signinwithemail&password is not a function TypeError: (0, firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.getFireStore) 在尝试使用 getFireStore function 时不是 function - TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.getFireStore) is not a function when trying to use getFireStore function 使用 signInWithEmailAndPassword 时在 auth/wrong-password 上获取 Firebase User.ProviderID - Get Firebase User.ProviderID on auth/wrong-password when using signInWithEmailAndPassword 当用户更新其 email 时,Firebase - Firebase auth onUpdate cloud function for when a user updates their email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM