Angular2-jwt: JWT Interceptor does not attach header to the request (prod)

Created on 4 Oct 2018  路  7Comments  路  Source: auth0/angular2-jwt

Hi,

I use the version 2.0.0 with angular 6, but the JWT Interceptor does not attach header to the request, but this only occurs by executing the ng serve --prod or ng build --prod, generated in development mode it works without problems.

My configuration is as follows:

`export function tokenGetter () {
聽聽 return localStorage.getItem ('token');
}

const jwtConf: JwtModule = {
聽聽 config: {
聽聽聽聽 tokenGetter: tokenGetter,
聽聽聽聽 whitelistedDomains: environment.tokenWhitelistedDomains,
聽聽聽聽 blacklistedRoutes: environment.tokenBlacklistedRoutes
聽聽 }
}

@NgModule ({
聽聽 imports:
聽聽聽聽 FormsModule,
聽聽聽聽 CommonModule,
聽聽聽聽 JwtModule.forRoot (jwtConf),
聽聽聽聽 SecurityRoutingModule
聽聽 ]`

And the enviroments:

`export const environment = {
聽聽 production: true,
聽聽 origin: 'http://localhost:8080/api/',

聽聽 tokenWhitelistedDomains: ['localhost: 8080'],
聽聽 tokenBlacklistedRoutes: [new RegExp ('\ /oauth\/token')]
};`

I have tried in many ways, but without success.

Thank you.

All 7 comments

Is your prod environment localhost:8080 as well? Whitelisted domains don't need the port specified if they are standard port 80 or port 443.

Hi,

I put localhost to illustrate, but in my production environment the port being used is the 8080 as well.
I did several tests changing the enviroments, but to no avail.

Dear all,

Any suggestions or tips on what might be? I have not been able to resolve yet :/

Thank you.

I'm facing the same issue. If I inspect the value of JwtInterceptor.whitelistedDomains in prod mode, the domains with RegExp get striped and only the text ones do arrive to the constructor. In dev mode, both text and RegExp ones do arrive. Looks like an error in UglifyJS.

As a workaround, you can pass RegExp expressions to the configuration using a factory function.

I had the same problem fixed it by changing the environments

tokenWhitelistedDomains: ['localhost:8080'],
  tokenBlacklistedRoutes: ['localhost:8080\/oauth\/token']

I managed to fix it by removing the 'http/https' from the URL.

Have a look at the issue: #593

Thanks @willianfalbo, we will be adding this to the documentation so that people don't hit this problem in the future, as per #593

Was this page helpful?
0 / 5 - 0 ratings