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"
},
"rules": {
"rxjs/no-ignored-subscription": "error",
"rxjs/no-ignored-subscription": "warn",
"@angular-eslint/no-conflicting-lifecycle": "error",
"@angular-eslint/no-host-metadata-property": "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 { DOCUMENT } from '@angular/common';
import { UserPreferenceService } from '@users/user-preference.service';
import { getConfig } from '@iqser/common-ui';
import { AppConfig } from '@red/domain';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { NavigationEnd, Router } from '@angular/router';
import { filter, map, switchMap, take } from 'rxjs/operators';
function loadCustomTheme() {
const cssFileName = getConfig<AppConfig>().THEME;
@ -26,9 +26,7 @@ function loadCustomTheme() {
selector: 'redaction-root',
templateUrl: './app.component.html',
})
export class AppComponent implements OnDestroy {
readonly #subscription = new Subscription();
export class AppComponent {
constructor(
/** ViewContainerRef needs to be injected for the color picker to work */
readonly viewContainerRef: ViewContainerRef,
@ -37,28 +35,27 @@ export class AppComponent implements OnDestroy {
userPreferenceService: UserPreferenceService,
renderer: Renderer2,
private readonly _router: Router,
route: ActivatedRoute,
) {
renderer.addClass(inject(DOCUMENT).body, userPreferenceService.getTheme());
loadCustomTheme();
const sub = route.queryParamMap.subscribe(queryParams => this.#navigate(queryParams));
this.#subscription.add(sub);
const removeQueryParams = _router.events.pipe(
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() {
this.#subscription.unsubscribe();
}
#navigate(queryParams: ParamMap) {
if (queryParams.has('code') || queryParams.has('state') || queryParams.has('session_state')) {
return this._router.navigate([], {
queryParams: {
state: null,
session_state: null,
code: null,
},
queryParamsHandling: 'merge',
});
}
#removeKeycloakQueryParams() {
return this._router.navigate([], {
queryParams: {
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">
<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 }}
</a>
<mat-divider class="pb-3 pt-3"></mat-divider>

View File

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