If you put a cookie in the server side header, AngularJS will send this cookie all the time. U has nothing to do.
If you want to transfer the token in the header not to the cxookie on the Angular side, just do this: $httpProvider.defaults.headers.common['X-Auth'] = yourKey; in your configuration block.
Then, if you want to find out if the user is registered or if he got the rights, he simply implements the interceptor. This is a simple factory that you will always enter in responseIntercetors in your configuration block.
This factory will listen for every response from the server and, when implemented, you will check the response status code in case of an error:
401 β not registered 403 β do not allow
factory example:
myModule.factory('myHttpInterceptor', function ($q) { return function (promise) { return promise.then(function (response) {
Then put your factory in http responseIntercetors, like this in your con fig block:
myModule.config(function ($httpProvider) { $httpProvider.responseInterceptors.push('myHttpInterceptor'); });
Just keep in mind that this solution is deprecated in AngularJS 1.1.4 (still unstable) ...
factory should be a little different, just refer to this post for more info: AngularJS Intercept all responses in $ http JSON
Hope this helps
Thomas pons
source share