From 996976ac66c160e4223800162f142d6f1c09b4b9 Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Wed, 16 Dec 2015 14:55:07 +0000 Subject: [PATCH] fix(core): Remove duplicate angular interceptor Remove the interceptor defined in the users module Update the interceptor defined in the core module Update the respective test Fixes #1096 --- .../auth.interceptor.client.service.js | 6 ++-- .../auth.interceptor.client.tests.js | 5 +++- .../client/config/users.client.config.js | 30 ------------------- 3 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 modules/users/client/config/users.client.config.js diff --git a/modules/core/client/services/interceptors/auth.interceptor.client.service.js b/modules/core/client/services/interceptors/auth.interceptor.client.service.js index d8eb8b93..a4785f52 100644 --- a/modules/core/client/services/interceptors/auth.interceptor.client.service.js +++ b/modules/core/client/services/interceptors/auth.interceptor.client.service.js @@ -1,12 +1,14 @@ 'use strict'; -angular.module('core').factory('authInterceptor', ['$q', '$injector', - function ($q, $injector) { +angular.module('core').factory('authInterceptor', ['$q', '$injector', 'Authentication', + function ($q, $injector, Authentication) { return { responseError: function(rejection) { if (!rejection.config.ignoreAuthModule) { switch (rejection.status) { case 401: + // Deauthenticate the global user + Authentication.user = null; $injector.get('$state').transitionTo('authentication.signin'); break; case 403: diff --git a/modules/core/tests/client/interceptors/auth.interceptor.client.tests.js b/modules/core/tests/client/interceptors/auth.interceptor.client.tests.js index bfbd6c59..2eecd461 100644 --- a/modules/core/tests/client/interceptors/auth.interceptor.client.tests.js +++ b/modules/core/tests/client/interceptors/auth.interceptor.client.tests.js @@ -6,6 +6,7 @@ var authInterceptor, $q, $state, + Authentication, httpProvider; // Load the main application module @@ -16,10 +17,11 @@ httpProvider = $httpProvider; })); - beforeEach(inject(function(_authInterceptor_, _$q_, _$state_) { + beforeEach(inject(function(_authInterceptor_, _$q_, _$state_, _Authentication_) { authInterceptor = _authInterceptor_; $q = _$q_; $state = _$state_; + Authentication = _Authentication_; spyOn($q,'reject'); spyOn($state,'transitionTo'); })); @@ -56,6 +58,7 @@ }; var promise = authInterceptor.responseError(response); expect($q.reject).toHaveBeenCalled(); + expect(Authentication.user).toBe(null); expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin'); }); }); diff --git a/modules/users/client/config/users.client.config.js b/modules/users/client/config/users.client.config.js deleted file mode 100644 index 33e95071..00000000 --- a/modules/users/client/config/users.client.config.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -// Config HTTP Error Handling -angular.module('users').config(['$httpProvider', - function ($httpProvider) { - // Set the httpProvider "not authorized" interceptor - $httpProvider.interceptors.push(['$q', '$location', 'Authentication', - function ($q, $location, Authentication) { - return { - responseError: function (rejection) { - switch (rejection.status) { - case 401: - // Deauthenticate the global user - Authentication.user = null; - - // Redirect to signin page - $location.path('signin'); - break; - case 403: - // Add unauthorized behaviour - break; - } - - return $q.reject(rejection); - } - }; - } - ]); - } -]);