首页 > 解决方案 > reauthenticateWithCredential 错误获取错误 TypeError: credential._getReauthenticationResolver is not a function (firebase 9)

问题描述

我正在学习火力基地。现在想用 reauthenticateWithCredential() 更改密码。但得到这样的错误。

TypeError: credential._getReauthenticationResolver 不是函数

这是代码:

import { getAuth, reauthenticateWithCredential, signInWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
const user = auth.currentUser;

const credential = signInWithEmailAndPassword(auth, user.email, this.oldPassword);
reauthenticateWithCredential(user, credential).then(() => {
// User re-authenticated.
 console.log(credential)
}).catch((error) => {
 console.log(error)
});

谁能指出错误在哪里?

标签: javascriptfirebase

解决方案


也许仍然不太正确,但试一试:

import {
  getAuth,
  reauthenticateWithCredential,
  EmailAuthProvider,
} from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;

try {
 const credential = EmailAuthProvider.credential(
  user.email,
  this.oldPassword
 );
 reauthenticateWithCredential(user, credential).then(() => {
  // User re-authenticated.
  // Code...
 });
} catch (error) {
 console.log(error.message);
}

推荐阅读