akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.29k stars 7.96k forks source link

Custom interceptor is not called #1875

Open crissty opened 6 years ago

crissty commented 6 years ago

Issue type

I'm submitting a ... (check one with "x")

Issue description

Current behavior: I have a custom interceptor of angular included in AppModule, when I update the ngx-admin, the interceptor is not working, it is not called in several routes or it is call more than once.

Expected behavior: The interceptor should be called in every call.

Steps to reproduce: Update ngx-admin to last release.

Related code:

  providers: [
    { provide: APP_BASE_HREF, useValue: '/' },
    { provide: HTTP_INTERCEPTORS, useClass: AppInterceptor, multi: true, deps: [Router, AlertService] }
  ],

Other information:

npm, node, OS, Browser

# node --version
v8.11.3

# npm --version
6.4.1

Angular, Nebular

"@angular/core": "6.0.0",
"@nebular/auth": "2.0.1"
kharratahmed commented 6 years ago

1871

yggg commented 6 years ago

Hi @crissty. Do you have errors in dev tools console?

Probably related to https://github.com/akveo/nebular/issues/631.

pkulas commented 6 years ago

Same problem here, need to include on each lazy module providers with interceptor to get it working.

Prefix1802 commented 6 years ago

So what do you mean by latest release? is it master? or what? master is never latest unless you pull.

So far my interceptors are working. As a matter of fact i am going to start a new project now based on the latest master branche. So i will let you know if i run in any problems with regards to your question.

Show us your code so we can have a look at it.

Quote: "Same problem here, need to include on each lazy module providers with interceptor to get it working." <- as i said show us your code.

The reason i ask for code is because if you dont do DI properly your service will be instantiated as new and not for Root.

I hope you understand where i am going with this.

stenterwan commented 6 years ago

I've had this problem as well. I think it has something to do with the ng2-smart-table. Everytime I import the Ng2SmartTable module, my interceptor doesn't intercept and I have to specify it in the providers. Can you try and see if it is the same for you?

maihannijat commented 5 years ago

I have the same problem with the following code in app.module.ts:

providers: [
  {provide: APP_BASE_HREF, useValue: environment.baseHref},
  {provide: HTTP_INTERCEPTORS, useClass: NbAuthJWTInterceptor, multi: true},
  {provide: NB_AUTH_TOKEN_INTERCEPTOR_FILTER, useValue: (req) => filter(req)},
],

I am importing HttpClientModule only once in app.module.ts.

The HttpClient sends empty body - no token.

Using Angular 7 "@nebular/auth": "^3.0.1",

maihannijat commented 5 years ago

This worked for me:

provide: NB_AUTH_TOKEN_INTERCEPTOR_FILTER, useValue: (req) => {
      return false;
}
IgnacioYanjari commented 5 years ago

@stenterwan I use angular 7.2.0 and nebular 3.1.0, but when I import Ng2SmartTable that use ng2-completer, the interceptor failed, and that occurs because ng2-completer import HttpClientModule!!

In the github repository of ng2-completer someone opened an issue for the same problem. They deleted the HttpClientModule import in versión 3.0.0-beta.2.

I change my package.json and it's works, me and my partner created an issue !!

nileshnagarwal commented 5 years ago

I've had this problem as well. I think it has something to do with the ng2-smart-table. Everytime I import the Ng2SmartTable module, my interceptor doesn't intercept and I have to specify it in the providers. Can you try and see if it is the same for you?

An awesome find. I struggled for 2 days to make my Interceptor work. Finally, your tip did the trick. As stated by @IgnacioYanjari, I've updated ng2-completer to 3.0.0-beta.2. Interceptor works without any issues now.

BruneXX commented 5 years ago

Hi @nileshnagarwal I just wondering, updating ng2-completer to latest stable version, now is 3.0.2 will solve this problem? so I've mean, Is there no need then to import and add the interceptor into each module as a provider?

nileshnagarwal commented 5 years ago

Hi @nileshnagarwal I just wondering, updating ng2-completer to latest stable version, now is 3.0.2 will solve this problem? so I've mean, Is there no need then to import and add the interceptor into each module as a provider?

Hi @BruneXX I've been using ng2-completer version 3.0.0-beta.2 and have only added the interceptor to the providers in app.module.ts. No need to import it in each module separately.

BruneXX commented 5 years ago

Hi @nileshnagarwal excellent, I can confirm that it works with ng2-completer v3.0.2 thanks for your quick reply! :)