Noobmaster06
Noobmaster06

Reputation: 113

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?

Upvotes: 11

Views: 1768

Answers (2)

Md Shejan Mahamud
Md Shejan Mahamud

Reputation: 1

Use EmailAuthProvider from firebase/auth

import {EmailAuthProvider} from "firebase/auth";

make credential with EmailAuthProvider like this:

const credential = EmailAuthProvider.credential(user?.email,oldPassword );

Rest of your code will same, Just use this way to create credentials

Upvotes: 0

Kamal
Kamal

Reputation: 529

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

Upvotes: 16

Related Questions