I am trying to use tokens to handle my user authentication. I hit a bump in the road and I am not entirely sure where to go from here. I looked around a bit, and it looks like I should use the $injector
service, but I am not 100% sure. Could anyone please assist?
I created a factory that gets the token from node:
angular.module('myApp').factory('authenticateInterceptor', function(authenticateToken){
var authenticateInterceptorFactory = {};
authenticateInterceptorFactory.request = function(config){
var token = authenticateToken.getToken();
if(token){
config.headers['x-access-token'] = token;
};
return config;
}
return authenticateInterceptorFactory;
});
Here is the code for autenticateToken:
angular.module('myApp').factory('authenticateToken', function($http, $window){
authenticateTokenFactory = {};
authenticateTokenFactory.getToken = function(token){
return $window.localStorage.getItem('token');
};
return authenticateTokenFactory;
});
There are no errors here, the problem comes in when I try to use this factory in my app.js.
angular.module('myApp', [
'dependancies goes here'
])
.config(function($httpProvider){
$httpProvider.interceptors.push('authenticateInterceptor');
});
This now causes the error, I can't seem to pass my factory into the interceptors.