I am working with a node js rest api. In the authentication process api returns an access token. I need to add the access token to every request from an common place.
Asked
Active
Viewed 3,441 times
1
-
1http://stackoverflow.com/questions/23244809/angular-js-set-token-on-header-default – Divyesh Savaliya Mar 07 '16 at 05:12
-
Take a look into angular js interceptors, this will satisfy your requirements. Using interceptors you can `intercept` the request `before` sending it to the server and same `after` the response is returned – Anonymous Duck Mar 07 '16 at 05:16
-
thanks for the quick response. yes this is what I needed. – Dushantha Mar 07 '16 at 05:20
1 Answers
3
You can use http interceptor
Code looks like as follow
$httpProvider.interceptors.push(function($q, $cookies) {
return {
'request': function(config) {
config.headers['Token'] = $cookies.loginTokenCookie;
return config;
}
};
});

Community
- 1
- 1

Divyesh Savaliya
- 2,692
- 2
- 18
- 37