Reputation: 1717
I'm wondering why everybody asking about 'setting default headers' in Restangular for authorization, but there's no info how to clear this header if user do 'log out'.
I do:
Restangular.setDefaultHeaders({Authorization: accessToken});
How to manually remove this header?
Upvotes: 2
Views: 1408
Reputation: 7886
You can use addRequestInterceptor to set Authorization to null
before each request if no valid token is available like :
Restangular.addRequestInterceptor(
function(element, operation, what, url) {
var accessToken = user.isLoggedIn() ? user.access_token : null;
Restangular.setDefaultHeaders({'Authorization': accessToken});
return element;
});
Or you can use addfullrequestinterceptor to apply any logic you need to your headers before sending any of them.
Upvotes: 0
Reputation: 2423
In documentation there isn't information about it. But you can get default headers via Restangular.defaultHeaders properly. So i suppose that you can reset or remove header from there.
Upvotes: 0