witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

Failed to instantiate module http-auth-interceptor #52

Closed dirtiestharp closed 10 years ago

dirtiestharp commented 10 years ago

I am trying to integrate http-auth-interceptor into mean.io (express / angular), but keep receiving the following error:

Error: [$injector:modulerr] Failed to instantiate module mean due to:
    Error: [$injector:modulerr] Failed to instantiate module http-auth-interceptor due to:
    Error: [$injector:nomod] Module 'http-auth-interceptor' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

I am using AngularJS 1.2.4 and I have http-auth-interceptor.js located in /public/lib/http-auth-interceptor/http-auth-interceptor.js

This is what my app.js looks like

angular.module('mean', [
            'http-auth-interceptor',
            'ngCookies', 
            'ngResource', 
            'ngRoute', 
            'ui.bootstrap', 
            'ui.route',
            'mean.system', 
            'mean.articles', 
            'login'])
/**
   * This directive will find itself inside HTML as a class,
   * and will remove that class, so CSS will remove loading image and show app content.
   * It is also responsible for showing/hiding login form.
   */
  .directive('meanApplication', function() {
    return {
      restrict: 'C',
      link: function(scope, elem, attrs) {
        //once Angular is started, remove class:
        elem.removeClass('waiting-for-angular');

        var login = elem.find('#login-holder');
        var main = elem.find('#content');

        login.hide();

        scope.$on('event:auth-loginRequired', function() {
          login.slideDown('slow', function() {
            main.hide();
          });
        });
        scope.$on('event:auth-loginConfirmed', function() {
          main.show();
          login.slideUp();
        });
      }
    };
  });

angular.module('mean.system', []);
angular.module('mean.articles', []);
angular.module('login', []);

And my login.js controller looks like this:

angular.module('login', ['http-auth-interceptor']).controller('LoginController', ['$scope', '$http', '$cookies', '$routeParams', '$location', 'Global' function ($scope, $http, authService, $cookies, $routeParams, $location, Global) {
    $scope.global = Global;
    $scope.csrfToken = $cookies['XSRF-TOKEN'];

    $scope.submit = function() {
      $http.post('/users/session').success(function() {
        authService.loginConfirmed();
      });
    };

}]);

And I am loading http-auth-interceptor.js in the footer like this:

<!--AngularJS-->
    <script type="text/javascript" src="/lib/angular/angular.js"></script>
    <script type="text/javascript" src="/lib/angular-cookies/angular-cookies.js"></script>
    <script type="text/javascript" src="/lib/angular-resource/angular-resource.js"></script>
    <script type="text/javascript" src="/lib/angular-route/angular-route.js"></script>
    <script type="text/javascript" src="/lib/http-auth-interceptor/http-auth-interceptor.js"></script>
    <!--Angular UI-->
    <script type="text/javascript" src="/lib/angular-bootstrap/ui-bootstrap.js"></script>
    <script type="text/javascript" src="/lib/angular-bootstrap/ui-bootstrap-tpls.js"></script>
    <script type="text/javascript" src="/lib/angular-ui-utils/modules/route/route.js"></script>
    <!--Application Init-->
    <script type="text/javascript" src="/js/app.js"></script>
    <script type="text/javascript" src="/js/config.js"></script>
    <script type="text/javascript" src="/js/directives.js"></script>
    <script type="text/javascript" src="/js/filters.js"></script>
    <!--Application Services-->
    <script type="text/javascript" src="/js/services/global.js"></script>
    <script type="text/javascript" src="/js/services/articles.js"></script>
    <!--Application Controllers-->
    <script type="text/javascript" src="/js/controllers/login.js"></script>
    <script type="text/javascript" src="/js/controllers/articles.js"></script>
    <script type="text/javascript" src="/js/controllers/index.js"></script>
    <script type="text/javascript" src="/js/controllers/header.js"> </script>
    <script type="text/javascript" src="/js/init.js"></script>

When the page is loaded I am able to click on and open http-auth-interceptor.js from view-source. I know I am missing something obvious, please let me know if you need any more information.

Thanks, DH

dirtiestharp commented 10 years ago

Figured it out. This error was being thrown by karma. Updated karma.conf.js with the correct http-auth-interceptor.js path and it went away.