Search code examples
angularjsnode.jsaccess-token

Add access token to every request header in Angular js


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.


Solution

  • 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;
        }
      };
    });
    

    From this post