Implement clean logout to fully clear app state and tokens

This commit is contained in:
aditya.chandel
2025-08-11 13:30:37 -06:00
committed by Aditya Chandel
parent 964b8e7f67
commit ec5157464a
32 changed files with 638 additions and 425 deletions
@@ -1,6 +1,6 @@
import {inject, Injectable, Injector} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {BehaviorSubject, Observable, tap} from 'rxjs';
import {BehaviorSubject, Observable, Subject, tap} from 'rxjs';
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
import {API_CONFIG} from '../../config/api-config';
import {createRxStompConfig} from '../../shared/websocket/rx-stomp.config';
@@ -23,6 +23,9 @@ export class AuthService {
private tokenSubject = new BehaviorSubject<string | null>(this.getOidcAccessToken() || this.getInternalAccessToken());
public token$ = this.tokenSubject.asObservable();
private logoutSubject = new Subject<void>();
public logout$ = this.logoutSubject.asObservable();
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
return this.http.post<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/login`, credentials).pipe(
tap((response) => {
@@ -78,6 +81,7 @@ export class AuthService {
localStorage.removeItem('accessToken_Internal');
localStorage.removeItem('refreshToken_Internal');
this.tokenSubject.next(null);
this.logoutSubject.next();
this.getRxStompService().deactivate();
if (this.oAuthService.clientId) {
this.oAuthService.logOut();