Angular2-jwt: Ability to change global headers after initialization

Created on 26 Jan 2017  路  8Comments  路  Source: auth0/angular2-jwt

The global headers feature is really neat, but it would be even better if I could change it dynamically after AuthHttp has been initialized. For example, I would like to set the Accept-Language header to the language chosen by the user, and if the user changes its language (which I can observe), then I would like to change this global header value for all http requests to come until further notice. Unfortunately, based on what I can understand in the code, currently you can only set global headers on initialization, or set them per request.

Most helpful comment

@sarbogast Can you show me an example of your code how did you handle this issue? I have very similar problem

All 8 comments

Wrap AuthHttp/Http and do it there. That said, we keep a reference to the global headers object, so if you had a reference to it elsewhere, you could change it at runtime. I'm not going to support issues with that though.

I ended up doing that for now, but it's messy. It would be much cleaner with global headers IMO.

Not really. You should be wrapping it already for other custom functionality you want to add to your requests, like error logging.

I admit that wrapping Http is harder than it should be. I don't know what happened with the rewrite intended to fix that.

Yes, basically I figured that when I override the request method, I have to treat url differently depending on whether it's a string or not, otherwise the headers I add can get ignored.

@sarbogast Can you show me an example of your code how did you handle this issue? I have very similar problem

Changing the reference does not seem to do any changes... (as well as setGlobalHeaders())

Any updates on that topic?

Closing as global headers has been removed from the latest versions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kolkov picture kolkov  路  3Comments

getglad picture getglad  路  5Comments

ciesielskico picture ciesielskico  路  5Comments

nickraphael picture nickraphael  路  3Comments

hang321 picture hang321  路  4Comments