Search code examples
javascriptfirebasefirebase-authenticationreact-redux-firebase

TypeError: Cannot read property 'credential' of undefined - React-redux-firebase, Firebase Auth


I have been developing a project where the user can change password. I want to reauthenticate the current user using

currentUser.reauthenticateWithCredential(
            firebase
              .auth()
              .EmailAuthProvider.credential(
                currentUser.email,
                credentials.userOldPassword
              )
          )
          .then(() => console.log("authenticated"))
          .catch((error) => console.log(error));

But it gives an error like

Cannot read property 'credential' of undefined

I am using react-redux-firebase


Solution

  • The EmailProvider class is in the auth namespace, not in the auth instance. So the correct syntax is:

    firebase
      .auth // no parenthesis here
      .EmailAuthProvider.credential(
        currentUser.email,
        credentials.userOldPassword
      )
    

    Also see the Firebase documentation for the EmailAuthProvider.credential method.