2

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?

3 Answers 3

2
Restangular.setDefaultHeaders({})

This will do the trick

Sign up to request clarification or add additional context in comments.

1 Comment

this will clean every custom headers, but not only 'Authorization' ;)
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.