TypeError: this.mRef.auth不是一个函数

TypeError: this.mRef.auth is not a function

本文关键字:一个 函数 this mRef auth TypeError      更新时间:2023-09-26

返回一个新的错误。现在正在进行身份验证。使用AngularJS和firebase。现在,当我在点击提交按钮时运行我的函数时,我在控制台中得到这个"TypeError: this. mref .auth不是一个函数"。我认为这很简单,但这是我的登录控制器:

.controller('Login', ['$scope', 'angularFire',
    function($scope, angularFire) {
        $scope.signin = function(){
            var ref = "https://myappurl.firebaseio.com";
            var auth = new FirebaseAuthClient(ref, function(error, user) {
                if (user) {
                // user authenticated with Firebase
                console.log(user);
            } else if (error) {
                 // an error occurred authenticating the user
                 console.log(error);
                } else {
                // user is logged out
                console.log("hello");
            }
        });
            console.log($scope);
            var user = $scope.cred.user;
            var pass = $scope.cred.password;
            auth.login('password', {
                email: user,
                password: pass,
                rememberMe: false
            });
        }
}])

接下来是html。我把它放在一个名为login的控制器中下面是它的内容:

<div class="inner loginbox" ng-controler="Login"
     <fieldset>
            <label class ="white">Username</label>
            <input type="text" id="username" ng-model="cred.user">
            <span class="help-block"></span>
            <label class ="white">Password</label>
            <input type="password" id="password" ng-model="cred.password">
            <div class="centerit rem-me">
                <label class="checkbox">
                    <div class="white">Remember me?
                        <input type="checkbox" ng-model="cred.remember">
                    </div>
                </label>
            </div>
            <div class="spacer1">
            </div>
            <a class="btn btn-inverse btn-large btn-width" id="signupsubmit" ng-click="signin()">Sign in</a>
    </fieldset>
</div>

我得到的类型错误指向第79行上的firebase-auth-client.js。在chrome中,我在控制台有这个:未捕获的TypeError:对象https://kingpinapp.firebaseio.com没有方法'auth'

在实例化FirebaseAuthClient时,您应该传递一个实际的Firebase引用,而不仅仅是一个引用的字符串表示形式。

使用下面的代码片段更新你的代码应该可以解决你的问题:

var ref = new Firebase("https://myappurl.firebaseio.com");
var auth = new FirebaseAuthClient(ref, function(error, user) {