Fixed minor issues with login & logout. Cleaned up the UI.

This commit is contained in:
Tom
2025-01-09 18:11:44 +00:00
parent d595c3500e
commit 2692294b4b
8 changed files with 128 additions and 86 deletions

View File

@ -1,67 +1,72 @@
import { CommonModule, isPlatformBrowser } from '@angular/common';
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, Inject, PLATFORM_ID, NgZone, OnDestroy } from '@angular/core';
import { Router, RouterOutlet } from '@angular/router';
import { FormsModule } from '@angular/forms'
import { HermesClientService } from './hermes-client.service';
import { AuthUserGuard } from './shared/auth/auth.user.guard'
import { Subscription } from 'rxjs';
import { NavigationComponent } from "./navigation/navigation.component";
import EventService from './shared/services/EventService';
import { ApiAuthenticationService } from './shared/services/api/api-authentication.service';
import { PoliciesModule } from './policies/policies.module';
import { TtsFiltersModule } from './tts-filters/tts-filters.module';
import { AuthModule } from './auth/auth.module';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, CommonModule, FormsModule, PoliciesModule, TtsFiltersModule, AuthModule, NavigationComponent],
providers: [AuthUserGuard],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, AuthModule, NavigationComponent],
providers: [AuthUserGuard],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent implements OnInit, OnDestroy {
private isBrowser: boolean;
private ngZone: NgZone;
private subscriptions: Subscription[];
private isBrowser: boolean;
private ngZone: NgZone;
private subscriptions: Subscription[];
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private router: Router, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
this.ngZone = ngZone;
this.isBrowser = isPlatformBrowser(this.platformId);
this.subscriptions = [];
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private router: Router, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
this.ngZone = ngZone;
this.isBrowser = isPlatformBrowser(this.platformId);
this.subscriptions = [];
}
ngOnInit(): void {
if (!this.isBrowser)
return;
this.auth.update();
this.addSubscription(this.events.listen('logoff', async (message) => {
localStorage.removeItem('jwt');
if (!document.location.href.includes('/login')) {
if (message)
await this.router.navigate(['login'], {
queryParams: { message: message }
});
else
await this.router.navigate(['login']);
}
}));
this.addSubscription(this.events.listen('login', async (_) => {
if (['/login', '/auth'].some(partial => document.location.href.includes(partial))) {
await this.router.navigate(['tts-login']);
}
}));
const connection = this.client.connect();
if (connection) {
this.addSubscription(connection);
}
this.ngZone.runOutsideAngular(() => setInterval(() => this.client.heartbeat(), 15000));
}
ngOnInit(): void {
if (!this.isBrowser)
return;
this.auth.update();
this.addSubscription(this.events.listen('logoff', (message) => {
localStorage.removeItem('jwt');
if (!document.location.href.includes('/login')) {
this.router.navigate(['/login?warning=' + message]);
}
}));
this.addSubscription(this.events.listen('login', (_) => {
if (document.location.href.includes('/login')) {
this.router.navigate(['/tts-login']);
}
}));
this.client.connect();
this.ngZone.runOutsideAngular(() => setInterval(() => this.client.heartbeat(), 15000));
ngOnDestroy() {
for (let s of this.subscriptions) {
s.unsubscribe();
}
}
ngOnDestroy() {
for (let s of this.subscriptions) {
s.unsubscribe();
}
}
private addSubscription(s: Subscription) {
this.subscriptions.push(s);
}
private addSubscription(s: Subscription) {
this.subscriptions.push(s);
}
}