Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'credential' of undefined with firebase reauthenticateWithCredential

Not exactly sure what I am doing wrong here, I have looked at other forum post and this is what they say to do to re-auth a user. But I am getting an error of:

TypeError: Cannot read property 'credential' of undefined on this line here:

const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);

Here is the code:

 const currentUser = fire.auth().currentUser;
 const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
 currentUser
  .reauthenticateWithCredential(credentials)
  .then(() => {
    alert('Success');
  })
  .catch(err => {
    alert(err);
  });
like image 513
Taylor Austin Avatar asked Jan 15 '18 21:01

Taylor Austin


2 Answers

Like @bojeil answered, it's a namespace so, for instance and if you're using typescript and you used firebase.initializeApp(config); in another class, just add again the import in the class where you user the credential method with import * as Firebase from 'firebase/app';

As u can see in the doc credential it's a static method in a static class that's why you need the namespace.

like image 67
somejhereandthere Avatar answered Nov 19 '22 15:11

somejhereandthere


You've imported firebase in the wrong way. Here is what it says in the document. Official Document

const firebase = require('firebase');
const cred = firebase.auth.EmailAuthProvider.credential(
    email,
    password
);
like image 20
davychhouk Avatar answered Nov 19 '22 17:11

davychhouk