Fyodor Khruschov
Fyodor Khruschov

Reputation: 1717

Remove default headers with Restangular

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

Answers (3)

Salem Ouerdani
Salem Ouerdani

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

Bleja_
Bleja_

Reputation: 61

Restangular.setDefaultHeaders({})

This will do the trick

Upvotes: 2

Errorpro
Errorpro

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

Related Questions