'fetchSignInMethodsForEmail(email) is not a function

I'm trying to make sure an email exist/ doesn't exist in firebase, but the method I'm trying to use does not seem to work.

This is my current code:

export function checkEmail(email) {
  return dispatch => {
    dispatch(checkEmailRequest());

    return window.firebase
      .auth()
      .fetchSignInMethodsForEmail(email)
      .then(results => {
        dispatch(checkEmailSuccess(results));
      })
      .catch(function(error) {
        dispatch(checkEmailFailed(error));
      });
  };
}

Message: TypeError: window.firebase.auth(...).fetchSignInMethodsForEmail is not a function



Solution 1:[1]

My first guess is that you're using an older version of the Firebase JavaScript SDK, while fetchSignInMethodsForEmail was introduced in version 6.0. Before that it was called fetchProvidersForEmail. So you'll either have to upgrade to a later version of the SDK, or use the older method.

Solution 2:[2]

For the the new modular version it's done like this:

import { fetchSignInMethodsForEmail } from 'firebase/auth';

fetchSignInMethodsForEmail(auth, email).then((result) => {
  console.log(result);
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen
Solution 2 Jonathan Laliberte