Home > other >  error with reauthenticateWithCredential get error TypeError: credential._getReauthenticationResolver
error with reauthenticateWithCredential get error TypeError: credential._getReauthenticationResolver

Time:09-17

I am learning firebase. now want to change password with reauthenticateWithCredential(). but get error like this.

TypeError: credential._getReauthenticationResolver is not a function

this the code:

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)
});

can anyone point out where the error is?

CodePudding user response:

Maybe still not quite right, but give this a try :

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);
}
  • Related