2muchcoffeecom / ng2-restangular

Restangular for Angular 2 (RENAMED DUE TO ANGULAR SEMVER)
http://ngx-restangular.com
MIT License
26 stars 7 forks source link

Late initialization of RestangularConfigFactory #2

Closed tomerpeled closed 7 years ago

tomerpeled commented 7 years ago

Currently I'm initializing the Restangular module via my main app.module from the import section: RestangularModule.forRoot(RestangularConfigFactory)

In this this function I'm setting setDefaultHeaders to use a token (I'm taking the token from the local storage - it is saved there after a success login) for each request. It works as expected :)

I do have an issue with my app flow.. Basically I have a login page (which is part of the app.module) and all the requests after a successful login, should use the token. However, for the first time login, the RestangularConfigFactory is called before the token is even exists so the next requests won't send any token...

How can I set the setDefaultHeaders for each request? but to set it only after a specific action, in this case after a successful login.

Thanks, Tomer

tomerpeled commented 7 years ago

So currently I just solve this issue with: RestangularConfigurer.setDefaultHeaders using restangular.withConfig...