Devextreme-angular: Interceptors stopped working

Created on 17 May 2018  路  11Comments  路  Source: DevExpress/devextreme-angular

After upgrading to version 18.1.3, the interceptors stopped working, version 17.2.7 it works normally.

devexteme version: 18.1.3
devextreme-angular version: 18.1.3

[x] bug Report
[ ] feature request
[ ] support inquiry

All 11 comments

Please provide me with a sample project that reproduces the issue.

Same issue.
I have this code below in the interceptor:
request = request.clone({ headers: request.headers.set('Authorization', authToken) });

This code below works fine in 17.2.7

      let me = this;
      this.dataSource.store = new CustomStore({
        load: function (loadOptions) {
          return me.service.getAll(loadOptions, me.myTasksOnly, me.showCompletedTasks, me.fromDate, me.toDate).toPromise().then(json => {
            return json;
          })
        },
        key: "idTask"
      });

Check the image attached, no Authorization included in the request header.
untitled

online sample code https://stackblitz.com/edit/angular-xcuxyl - v17.2.8 work
but stackblitz don't allow update to new version.

@granella I checked it with version 18.1.2-beta.1, but the result is the same
https://stackblitz.com/edit/angular-gwxetn

@granella,

If you don't use our CustomStore, does your code to request your server work?

it is very weird to me.
with out devextreme custom store, some of the API's are sent with JWT tokens and some are not.
Also, I have one of the pages with Devextreme custom store and was calling the API with token.

Most of my API calls are are not injecting the JWT.
I reverted back the devextreme to 17.2.x and everything went back fine.

I found the issue, will write the reason shortly.
Just to make sure.

The issue was:
All service files that are add to app.module--> providers were working fine.
All service files that are added to lazy loaded modules -->providers had this issue.

I moved all service files into 1 folder (_services) and I added them to the app.module-->providers.

I don't know if this is the best practice.

I have the exact same problem.
The probable reason is that Devextreme feature modules imports HttpClientModule which should be imported only once in the root application module. It resets internal state of interceptors for lazy loaded routes.
More info: https://github.com/angular/angular/issues/20575

EDIT:
I had a problem because my shared module imported devextreme modules and shared module was lazy loaded. All requests from within any feature module were ignoring my interceptors. Good thing - I had only one Authorization interceptor provided by myself so I moved provider from core module to shared module. All modules that import shared module have its own copy of interceptor.
This solution works only for simple cases though. If for some reason you need singleton interceptor or you cannot know your interceptor list beforehand it will not work.

@MateuszBogdan is correct, having the HttpClientModule imported again is overriding the interceptors, which shouldn't be done. Likewise his solution won't work in most cases, devextreme likely needs to find a way around that. We will be reverting to 17 and not updating until this is fixed.

Is this issue resolved? i'm having the same problem on devextreme 18.1.5

Was this page helpful?
0 / 5 - 0 ratings