Fixed API keys not swapping properly when impersonating.

This commit is contained in:
Tom 2025-04-02 19:56:21 +00:00
parent fcf1e9ac03
commit b465f0a474
2 changed files with 27 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { Component, inject, OnInit } from '@angular/core'; import { Component, inject, OnDestroy, OnInit } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatSelectModule } from '@angular/material/select'; import { MatSelectModule } from '@angular/material/select';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
@ -6,6 +6,9 @@ import { MatButtonModule } from '@angular/material/button';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { HermesClientService } from '../../hermes-client.service'; import { HermesClientService } from '../../hermes-client.service';
import { MatCardModule } from '@angular/material/card'; import { MatCardModule } from '@angular/material/card';
import EventService from '../../shared/services/EventService';
import { Subscription } from 'rxjs';
import { ApiKeyService } from '../../shared/services/api/api-key.service';
@Component({ @Component({
selector: 'tts-login', selector: 'tts-login',
@ -20,16 +23,30 @@ import { MatCardModule } from '@angular/material/card';
templateUrl: './tts-login.component.html', templateUrl: './tts-login.component.html',
styleUrl: './tts-login.component.scss' styleUrl: './tts-login.component.scss'
}) })
export class TtsLoginComponent implements OnInit { export class TtsLoginComponent implements OnInit, OnDestroy {
private readonly client = inject(HermesClientService); private readonly client = inject(HermesClientService);
private readonly route = inject(ActivatedRoute); private readonly route = inject(ActivatedRoute);
private readonly keyService = inject(ApiKeyService);
private readonly eventService = inject(EventService);
keyControl = new FormControl<string | null>(''); keyControl = new FormControl<string | null>('');
api_keys: { id: string, label: string }[] = []; api_keys: { id: string, label: string }[] = [];
subscriptions: (Subscription | null)[] = [];
ngOnInit(): void { ngOnInit(): void {
this.route.data.subscribe(d => this.api_keys = d['keys']); this.route.data.subscribe(d => this.api_keys = d['keys']);
this.subscriptions.push(this.eventService.listen('impersonation', _ => this.reset()));
this.subscriptions.push(this.eventService.listen('logoff', _ => this.reset()));
}
ngOnDestroy(): void {
for (let subscription of this.subscriptions) {
if (subscription) {
subscription.unsubscribe();
}
}
} }
login(): void { login(): void {
@ -38,4 +55,9 @@ export class TtsLoginComponent implements OnInit {
this.client.login(this.keyControl.value); this.client.login(this.keyControl.value);
} }
private reset() {
this.api_keys = [];
this.keyService.fetch().subscribe(keys => this.api_keys = keys);
}
} }

View File

@ -16,11 +16,9 @@ export class ApiKeyService {
constructor() { constructor() {
this.events.listen('tts_logoff', (impersonation) => { this.events.listen('impersonation', () => {
if (impersonation) { this.keys = [];
this.keys = []; this.loaded = false;
this.loaded = false;
}
}); });
this.events.listen('logoff', () => { this.events.listen('logoff', () => {