From 2c6d5a755fc8453ba21410bf5e6cb104cdcffa96 Mon Sep 17 00:00:00 2001 From: Constantin Simonis Date: Wed, 7 May 2025 14:51:02 +0200 Subject: [PATCH] fix: fix stupid ahh bug where u get logged out when doing fucking anything stupid fucking http interceptor --- frontend/src/app/app.component.ts | 10 ++++++++-- frontend/src/app/app.config.ts | 6 ------ frontend/src/app/service/auth.service.ts | 7 ++++--- .../src/app/shared/interceptor/http.interceptor.ts | 7 +++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 0d82bed..d32e722 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterOutlet } from '@angular/router'; import { FooterComponent } from './shared/components/footer/footer.component'; @@ -12,4 +12,10 @@ import { FooterComponent } from './shared/components/footer/footer.component'; styleUrl: './app.component.css', changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AppComponent {} +export class AppComponent implements OnInit { + ngOnInit() { + const count = +(localStorage.getItem('reloadCount') ?? 0); + localStorage.setItem('reloadCount', (count + 1).toString()); + console.log('Reload count from localStorage:', count + 1); + } +} diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index d6ac35a..679c5e4 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -5,7 +5,6 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { routes } from './app.routes'; import { provideHttpClient, withInterceptors } from '@angular/common/http'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; -import { OAuthStorage, provideOAuthClient } from 'angular-oauth2-oidc'; import { httpInterceptor } from '@shared/interceptor/http.interceptor'; export const appConfig: ApplicationConfig = { @@ -15,10 +14,5 @@ export const appConfig: ApplicationConfig = { provideHttpClient(withInterceptors([httpInterceptor])), provideExperimentalZonelessChangeDetection(), provideAnimationsAsync(), - provideOAuthClient(), - { - provide: OAuthStorage, - useFactory: () => localStorage, - }, ], }; diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts index 4445af8..7880000 100644 --- a/frontend/src/app/service/auth.service.ts +++ b/frontend/src/app/service/auth.service.ts @@ -8,8 +8,8 @@ import { AuthResponse } from '../model/auth/AuthResponse'; import { User } from '../model/User'; import { environment } from '@environments/environment'; -const TOKEN_KEY = 'auth-token'; -const USER_KEY = 'auth-user'; +const TOKEN_KEY = 'token'; +const USER_KEY = 'user'; @Injectable({ providedIn: 'root', @@ -88,7 +88,8 @@ export class AuthService { next: (user) => { this.setUser(user); }, - error: () => { + error: (e) => { + console.log(e); this.logout(); }, }); diff --git a/frontend/src/app/shared/interceptor/http.interceptor.ts b/frontend/src/app/shared/interceptor/http.interceptor.ts index 2cce8d0..2ff7788 100644 --- a/frontend/src/app/shared/interceptor/http.interceptor.ts +++ b/frontend/src/app/shared/interceptor/http.interceptor.ts @@ -1,10 +1,9 @@ import { HttpInterceptorFn } from '@angular/common/http'; -import { inject } from '@angular/core'; -import { AuthService } from '../../service/auth.service'; + +const TOKEN_KEY = 'token'; export const httpInterceptor: HttpInterceptorFn = (req, next) => { - const authService = inject(AuthService); - const token = authService.getToken(); + const token = localStorage.getItem(TOKEN_KEY); // Always add CORS headers if (token) {