Implement clean logout to fully clear app state and tokens
This commit is contained in:
committed by
Aditya Chandel
parent
964b8e7f67
commit
ec5157464a
@@ -1,15 +1,26 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {inject, Injectable, OnDestroy} from '@angular/core';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, takeUntil} from 'rxjs/operators';
|
||||
import {Subject} from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ReaderPreferencesService {
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class ReaderPreferencesService implements OnDestroy {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private currentUser: User | null = null;
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
constructor() {
|
||||
this.userService.userState$.subscribe(user => this.currentUser = user);
|
||||
this.userService.userState$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(userState => this.currentUser = userState.user);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
updatePreference(path: string[], value: any): void {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {filter, takeUntil} from 'rxjs/operators';
|
||||
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {UserService, UserSettings, UserState} from '../user-management/user.service';
|
||||
import {EpubReaderPreferencesComponent} from './epub-reader-preferences-component/epub-reader-preferences-component';
|
||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences-component/pdf-reader-preferences-component';
|
||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences-component/cbx-reader-preferences-component';
|
||||
@@ -27,22 +28,24 @@ export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
userData$: Observable<User | null> = this.userService.userState$;
|
||||
private subscription?: Subscription;
|
||||
userData$: Observable<UserState> = this.userService.userState$;
|
||||
userSettings!: UserSettings;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.userData$.subscribe(user => {
|
||||
if (user) {
|
||||
this.userSettings = user.userSettings;
|
||||
this.loadPreferences(user.userSettings);
|
||||
}
|
||||
this.userData$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(userState => {
|
||||
this.userSettings = userState.user!.userSettings;
|
||||
this.loadPreferences(userState.user!.userSettings);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription?.unsubscribe();
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private loadPreferences(settings: UserSettings): void {
|
||||
|
||||
Reference in New Issue
Block a user