Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom interceptor is not called #1875

Open
1 of 3 tasks
crissty opened this issue Oct 9, 2018 · 12 comments
Open
1 of 3 tasks

Custom interceptor is not called #1875

crissty opened this issue Oct 9, 2018 · 12 comments

Comments

@crissty
Copy link
Contributor

crissty commented Oct 9, 2018

Issue type

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

  • bug report
  • feature request
  • question about the decisions made in the repository

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
Copy link

#1871

@yggg
Copy link
Contributor

yggg commented Oct 16, 2018

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

Probably related to akveo/nebular#631.

@pkulas
Copy link

pkulas commented Oct 17, 2018

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

@Prefix1802
Copy link

Prefix1802 commented Oct 17, 2018

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
Copy link

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
Copy link

maihannijat commented Dec 20, 2018

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
Copy link

This worked for me:

provide: NB_AUTH_TOKEN_INTERCEPTOR_FILTER, useValue: (req) => {
      return false;
}

@IgnacioYanjari
Copy link

IgnacioYanjari commented Jan 17, 2019

@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
Copy link

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
Copy link

BruneXX commented Aug 30, 2019

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
Copy link

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
Copy link

BruneXX commented Aug 31, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants