Firebase:在测试期间我得到 "undefined is not a function"

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

这是我用过的代码:

var cred = firebase.auth().EmailAuthProvider($scope.data.mail, $scope.data.pwd);

firebase.auth().signInWithCredential(cred)
                                        .then(function()

在测试过程中,出现以下错误:

TypeError: undefined is not a function (evaluating 'firebase.auth().EmailAuthProvider($scope.data.mail, $scope.data.pwd)')

那么我的代码有什么问题?我该如何解决这个问题?

要通过 email/pass 登录用户,您只需调用 signInWithEmailAndPassword 方法。

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

然后你可以监听实时认证事件:

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.