Switch to localStorage for JWT handling and simplify case transformation logic in LoginComponent. Update app.config.ts and related services to align with the new token management method. Mark JwtClaims interface as exported.

This commit is contained in:
2025-07-06 19:10:17 +02:00
parent 54e747118c
commit 04310e1cce
6 changed files with 28 additions and 43 deletions
+14 -11
View File
@@ -1,26 +1,29 @@
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
import {ApplicationConfig, importProvidersFrom, provideZoneChangeDetection} from '@angular/core';
import {provideRouter} from '@angular/router';
import {JwtHelperService, JwtModule} from '@auth0/angular-jwt';
import {CookieService} from 'ngx-cookie-service';
import {routes} from './app.routes';
// Function to get the JWT token from cookies
export function jwtTokenGetter() {
const cookieService = new CookieService(document, null);
return cookieService.check('jwt') ? cookieService.get('jwt') : null;
return localStorage.getItem('jwt');
}
export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({eventCoalescing: true}),
provideRouter(routes),
{ provide: CookieService, useClass: CookieService },
{ provide: JwtHelperService, useClass: JwtHelperService },
{ provide: JwtModule, useValue: JwtModule.forRoot({
config: {
tokenGetter: jwtTokenGetter
}
})}
CookieService,
{
provide: JwtHelperService,
useValue: new JwtHelperService()
},
importProvidersFrom(
JwtModule.forRoot({
config: {
tokenGetter: jwtTokenGetter
}
})
)
]
};