$ firebaseAuthProvider< - $ firebaseAuth< - Auth

时间:2017-01-06 10:34:34

标签: javascript angularjs firebase firebase-authentication

我在Firebase中创建了1个用户帐户,我只需要对其进行身份验证,但收到的错误就像 $firebaseAuthProvider <- $firebaseAuth <- Auth

我的app.js:

    var mypractice = angular.module("firebase.appauth", ['practicecontroller','firebase','ngRoute','ngMessages' ]);

服务方法:我为身份验证创建了一个单独的工厂:

    mypractice.factory("Auth", ["$firebaseAuth",
        function($firebaseAuth) {
            var ref = $firebaseAuth(new Firebase("https://firabaseurl.com"));

            return $firebaseAuth(ref);
        }
    ]);

控制器:

practicecontroller.controller("loginctrl", ['$scope', '$http', 'Auth', function ($scope, $http, Auth) {
    $scope.auth = Auth;
    $scope.auth.$onAuth(function (authData) {
        $scope.authData = authData;
    });

    $scope.login = function () {
        Auth.$authWithPassword({
            email : $scope.username,
            password : $scope.password
        })
        .then(function (authData) {
            console.log('Logged in as:', authData.uid);

            window.location.href = "#/login/home"

        })
        .catch (function (err) {
            console.log('error:', err);
            //$state.go('login');
        });
    };

1 个答案:

答案 0 :(得分:0)

您不直接使用$firebaseAuth注入firebase。请参阅:https://firebase.google.com/docs/auth/web/manage-users

firebase.auth()...