我正在学习 firebase。现在想使用 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)
});
谁能指出错误在哪里吗?
也许仍然不太正确,但尝试一下:
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);
}
使用
EmailAuthProvider
中的
firebase/auth
import {EmailAuthProvider} from "firebase/auth";
使用
EmailAuthProvider
制作凭证,如下所示:
const credential = EmailAuthProvider.credential(user?.email,oldPassword );
您的其余代码将相同,只需使用这种方式来创建凭据