AngularFire v2 Firebase v3上的未知提供者:currentAuthProvider< - currentAuth

时间:2016-06-08 07:24:55

标签: angularjs angularfire firebase-authentication

我正在尝试让用户登录并在我的angularfire应用程序中从/ route继续。但是,当我在MainController中时,我得到了未知的提供程序错误。 这是我的工作;

var app = angular.module("myApp", ['firebase', 'ngRoute']);

这是firebaseAuth的工厂。

app.factory("Auth", ["$firebaseAuth",
  function($firebaseAuth) {
   return $firebaseAuth();
  }
]);

这是来自authenticating with routers angularfire教程。

app.run(["$rootScope", "$location", function($rootScope, $location) {
  $rootScope.$on("$routeChangeError", function(event, next, previous, error) {
    if (error === "AUTH_REQUIRED") {
      $location.path("/login");
    }
  });
}]);

app.config(["$routeProvider", function($routeProvider) {
  $routeProvider.when("/login", {
    controller: "LoginController",
    templateUrl: "views/login.html",
    resolve: {
      "currentAuth": ["Auth", function(Auth) {
        return Auth.$waitForSignIn();
      }]
    }
  }).when("/", {
    controller: "MainController",
    templateUrl: "views/home.html",
    resolve: {
      "currentAuth": ["Auth", function(Auth) {
        return Auth.$requireSignIn();
      }]
    }
  });
}]);

在登录页面我可以通过谷歌弹出登录,我可以在浏览器中看到cookie。

app.controller("LoginController", ["$scope", "currentAuth", "Auth", function($scope, currentAuth, Auth) {
  $scope.auth = Auth;

  $scope.auth.$onAuthStateChanged(function(firebaseUser) {
    $scope.firebaseUser = firebaseUser;
  });
}]);

当我打开" /"路径,它失败并创建像this

这样的错误
app.controller("MainController", [ "$scope", "$location", "$firebaseArray", "currentAuth", function($scope, $location, $firebaseArray, currentAuth) {
    var ref = firebase.database().ref();

    if (currentAuth == undefined || currentAuth == null) {
      $location.path('/login');
    }
}]);

我错过了什么错误吗?

谢谢。

0 个答案:

没有答案