Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error with reauthenticateWithCredential get error TypeError: credential._getReauthenticationResolver is not a function (firebase 9)

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?

like image 719
Noobmaster06 Avatar asked Sep 15 '21 01:09

Noobmaster06


1 Answers

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);
}
like image 172
Kamal Avatar answered Sep 18 '22 18:09

Kamal