user6039980 user6039980 - 1 year ago 365
Javascript Question

Firebase: During testing I get "undefined is not a function"

This is my used code:

var cred = firebase.auth().EmailAuthProvider($, $;


During testing, I get the following error:

TypeError: undefined is not a function (evaluating

So what's wrong with my code? How can I fix this problem?

Answer Source

To log a user in via email/pass you just call the signInWithEmailAndPassword method.

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...

Then you can listen for the realtime auth event:

firebase.auth().onAuthStateChanged(function(user) {
  if (user !== null) {
    console.log('logged in!');

Check the docs here for more on email login.

Check the API reference for onAuthStateChanged for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download