fix: fix stupid ahh bug where u get logged out when doing fucking anything stupid fucking http interceptor
This commit is contained in:
parent
fb4c7f175a
commit
2c6d5a755f
4 changed files with 15 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { RouterOutlet } from '@angular/router';
|
||||||
import { FooterComponent } from './shared/components/footer/footer.component';
|
import { FooterComponent } from './shared/components/footer/footer.component';
|
||||||
|
@ -12,4 +12,10 @@ import { FooterComponent } from './shared/components/footer/footer.component';
|
||||||
styleUrl: './app.component.css',
|
styleUrl: './app.component.css',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||||
import { routes } from './app.routes';
|
import { routes } from './app.routes';
|
||||||
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
||||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
import { OAuthStorage, provideOAuthClient } from 'angular-oauth2-oidc';
|
|
||||||
import { httpInterceptor } from '@shared/interceptor/http.interceptor';
|
import { httpInterceptor } from '@shared/interceptor/http.interceptor';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
|
@ -15,10 +14,5 @@ export const appConfig: ApplicationConfig = {
|
||||||
provideHttpClient(withInterceptors([httpInterceptor])),
|
provideHttpClient(withInterceptors([httpInterceptor])),
|
||||||
provideExperimentalZonelessChangeDetection(),
|
provideExperimentalZonelessChangeDetection(),
|
||||||
provideAnimationsAsync(),
|
provideAnimationsAsync(),
|
||||||
provideOAuthClient(),
|
|
||||||
{
|
|
||||||
provide: OAuthStorage,
|
|
||||||
useFactory: () => localStorage,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,8 @@ import { AuthResponse } from '../model/auth/AuthResponse';
|
||||||
import { User } from '../model/User';
|
import { User } from '../model/User';
|
||||||
import { environment } from '@environments/environment';
|
import { environment } from '@environments/environment';
|
||||||
|
|
||||||
const TOKEN_KEY = 'auth-token';
|
const TOKEN_KEY = 'token';
|
||||||
const USER_KEY = 'auth-user';
|
const USER_KEY = 'user';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
|
@ -88,7 +88,8 @@ export class AuthService {
|
||||||
next: (user) => {
|
next: (user) => {
|
||||||
this.setUser(user);
|
this.setUser(user);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: (e) => {
|
||||||
|
console.log(e);
|
||||||
this.logout();
|
this.logout();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { HttpInterceptorFn } from '@angular/common/http';
|
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) => {
|
export const httpInterceptor: HttpInterceptorFn = (req, next) => {
|
||||||
const authService = inject(AuthService);
|
const token = localStorage.getItem(TOKEN_KEY);
|
||||||
const token = authService.getToken();
|
|
||||||
|
|
||||||
// Always add CORS headers
|
// Always add CORS headers
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|
Reference in a new issue