RED-3800: fix keycloak query params removal

This commit is contained in:
Dan Percic 2023-06-09 16:13:57 +03:00
parent 1505dac3ac
commit 8810ae218d
4 changed files with 34 additions and 29 deletions

View File

@ -51,7 +51,7 @@
"project": "./tsconfig.json" "project": "./tsconfig.json"
}, },
"rules": { "rules": {
"rxjs/no-ignored-subscription": "error", "rxjs/no-ignored-subscription": "warn",
"@angular-eslint/no-conflicting-lifecycle": "error", "@angular-eslint/no-conflicting-lifecycle": "error",
"@angular-eslint/no-host-metadata-property": "error", "@angular-eslint/no-host-metadata-property": "error",
"@angular-eslint/no-input-rename": "error", "@angular-eslint/no-input-rename": "error",

View File

@ -1,11 +1,11 @@
import { Component, inject, OnDestroy, Renderer2, ViewContainerRef } from '@angular/core'; import { Component, inject, Renderer2, ViewContainerRef } from '@angular/core';
import { RouterHistoryService } from '@services/router-history.service'; import { RouterHistoryService } from '@services/router-history.service';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { UserPreferenceService } from '@users/user-preference.service'; import { UserPreferenceService } from '@users/user-preference.service';
import { getConfig } from '@iqser/common-ui'; import { getConfig } from '@iqser/common-ui';
import { AppConfig } from '@red/domain'; import { AppConfig } from '@red/domain';
import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { NavigationEnd, Router } from '@angular/router';
import { Subscription } from 'rxjs'; import { filter, map, switchMap, take } from 'rxjs/operators';
function loadCustomTheme() { function loadCustomTheme() {
const cssFileName = getConfig<AppConfig>().THEME; const cssFileName = getConfig<AppConfig>().THEME;
@ -26,9 +26,7 @@ function loadCustomTheme() {
selector: 'redaction-root', selector: 'redaction-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
}) })
export class AppComponent implements OnDestroy { export class AppComponent {
readonly #subscription = new Subscription();
constructor( constructor(
/** ViewContainerRef needs to be injected for the color picker to work */ /** ViewContainerRef needs to be injected for the color picker to work */
readonly viewContainerRef: ViewContainerRef, readonly viewContainerRef: ViewContainerRef,
@ -37,28 +35,27 @@ export class AppComponent implements OnDestroy {
userPreferenceService: UserPreferenceService, userPreferenceService: UserPreferenceService,
renderer: Renderer2, renderer: Renderer2,
private readonly _router: Router, private readonly _router: Router,
route: ActivatedRoute,
) { ) {
renderer.addClass(inject(DOCUMENT).body, userPreferenceService.getTheme()); renderer.addClass(inject(DOCUMENT).body, userPreferenceService.getTheme());
loadCustomTheme(); loadCustomTheme();
const sub = route.queryParamMap.subscribe(queryParams => this.#navigate(queryParams)); const removeQueryParams = _router.events.pipe(
this.#subscription.add(sub); filter((event): event is NavigationEnd => event instanceof NavigationEnd),
map(event => event.urlAfterRedirects),
filter(url => url.includes('code=') || url.includes('state=') || url.includes('session_state=')),
switchMap(() => this.#removeKeycloakQueryParams()),
take(1),
);
removeQueryParams.subscribe();
} }
ngOnDestroy() { #removeKeycloakQueryParams() {
this.#subscription.unsubscribe(); return this._router.navigate([], {
} queryParams: {
state: null,
#navigate(queryParams: ParamMap) { session_state: null,
if (queryParams.has('code') || queryParams.has('state') || queryParams.has('session_state')) { code: null,
return this._router.navigate([], { },
queryParams: { queryParamsHandling: 'merge',
state: null, });
session_state: null,
code: null,
},
queryParamsHandling: 'merge',
});
}
} }
} }

View File

@ -2,7 +2,12 @@
<ng-container *ngFor="let item of storedTenants | keyvalue; trackBy: trackBy"> <ng-container *ngFor="let item of storedTenants | keyvalue; trackBy: trackBy">
<div class="label">{{ item.key }}</div> <div class="label">{{ item.key }}</div>
<a (click)="selectTenant(stored.tenant.tenantId)" *ngFor="let stored of item.value" [id]="stored.tenant.tenantId" mat-menu-item> <a
(click)="selectTenant(stored.tenant.tenantId, stored.email)"
*ngFor="let stored of item.value"
[id]="stored.tenant.tenantId"
mat-menu-item
>
{{ stored.email }} {{ stored.email }}
</a> </a>
<mat-divider class="pb-3 pt-3"></mat-divider> <mat-divider class="pb-3 pt-3"></mat-divider>

View File

@ -22,9 +22,12 @@ export class TenantsMenuComponent {
return item.key; return item.key;
} }
selectTenant(tenantId?: string) { selectTenant(tenantId?: string, email?: string) {
const tenant = tenantId ? '/' + tenantId : '/'; let tenantUrl = tenantId ? '/' + tenantId + '/main' : '/';
window.open(window.location.origin + this.#baseHref + tenant, '_blank'); if (email) {
tenantUrl += '?username=' + email;
}
window.open(window.location.origin + this.#baseHref + tenantUrl, '_blank');
} }
#getStoredTenants(): Map<string, IStoredTenant[]> { #getStoredTenants(): Map<string, IStoredTenant[]> {