From 42f0961f13225469120b253b40b73f6354b07eab Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 6 Jul 2025 19:14:06 +0200 Subject: [PATCH] Directly initialize JwtHelperService in auth service --- frontend/src/app/app.config.ts | 18 +----------------- frontend/src/app/services/auth.service.ts | 4 ++-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 1e29c9a..34333cf 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -1,29 +1,13 @@ -import {ApplicationConfig, importProvidersFrom, provideZoneChangeDetection} from '@angular/core'; +import {ApplicationConfig, 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'; -export function jwtTokenGetter() { - return localStorage.getItem('jwt'); -} - export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({eventCoalescing: true}), provideRouter(routes), CookieService, - { - provide: JwtHelperService, - useValue: new JwtHelperService() - }, - importProvidersFrom( - JwtModule.forRoot({ - config: { - tokenGetter: jwtTokenGetter - } - }) - ) ] }; diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index 0b998bb..f88cc1c 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -15,11 +15,11 @@ export class AuthService { private userClaimsSubject = new BehaviorSubject(null); public userClaims$ = this.userClaimsSubject.asObservable(); + private jwtHelper = new JwtHelperService(); constructor( private loginService: LoginService, - private snackBar: MatSnackBar, - private jwtHelper: JwtHelperService + private snackBar: MatSnackBar ) { // Check if user is already logged in on service initialization this.checkAuthStatus();