'firebase auth is not a function

I got this TypeError: WEBPACK_IMPORTED_MODULE_4__firebase.c.auth is not a function

The line i got an error is the first line.

firebase.auth().createUserWithEmailAndPassword(email, password).then(authUser => {

          // Create a user in your own accessible Firebase Database too
          db.doCreateUser(authUser.user.uid, username, email, gender, coin, followers, followings)
            .then(() => {
              this.setState(() => ({ ...INITIAL_STATE }));
              history.push("/");
            })
            .catch(error => {
              this.setState(updateByPropertyName('error', error));
            });
        })
        .catch(error => {
          this.setState(updateByPropertyName('error', error));
        });
      //To prevent reloading of page after submit
      event.preventDefault();
      <Redirect to="/"/>;
    }

I'm trying to create user with email and password using firebase authentication. Also, i am adding all the info from the input to firebase realtime database. I've searching for an answer and all came out as nothing. Anyone know how to fix??



Solution 1:[1]

Did you import firebase correctly?

import * as firebase from 'firebase';

Solution 2:[2]

You have called a firebase method prior to initializing firebase firebase.init(config);

Solution 3:[3]

Yes because you have not created an instance of the Google provider.

const provider = new firebase.auth.GoogleAuthProvider();

now your code will execute

firebase
  .auth()
    .signInWithRedirect(provider)
    .then((result) => console.log(result))
    .catch((errors) => console.log(error));

More Info could be found here : firebase - link

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 Dylan Prem
Solution 2 Ronnie Royston
Solution 3 Amit Kumar