Skip to content

Authorization header stops going through after the browser sits idle for a while. #763

@hassanasad

Description

@hassanasad

I am facing a weird issue where the JWT interceptor stops sending the authorization header after the browser is sitting for a while and then if an API request is sent. I am unable to replicate this at will and thats why i dont have reproduction steps. I just see these being reported in the server logs intermittently.

I am on the latest available version 5.1.2 of JWT library
Angular 14.2.8
It happens from both MacOS and Windows on Chrome, Safari etc

It works fine for awhile and then same API calls start missing authorization header

This is the code snippet we have:

export function JwtTokenGetter(): string {
	if ( localStorage ) {
		return localStorage.getItem('token');
	} else {
		return window.localStorage.getItem('token');
	}
}

@NgModule({
	imports: [
		JwtModule.forRoot({
			config: {
				tokenGetter     : JwtTokenGetter,
				allowedDomains  : allowedDomains,
				disallowedRoutes: [new RegExp(/.*skipInterceptors=true.*/im)],
		},
		}),
		[...]
	],
	providers: [
		JwtInterceptor,	// Providing JwtInterceptor allow to inject JwtInterceptor manually into RefreshTokenInterceptor
		{
			provide    : HTTP_INTERCEPTORS,
			useExisting: JwtInterceptor,
			multi      : true,
		},
		{
			provide : HTTP_INTERCEPTORS,
			useClass: RefreshTokenInterceptor,
			multi   : true,
		},
		[...]
	]
})

Any ideas how to debug this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions