diff --git a/.eslintrc.json b/.eslintrc.json index 55573b760..67bcebc6d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/apps/red-ui/src/app/app.component.ts b/apps/red-ui/src/app/app.component.ts index ef9078aba..c980c07ed 100644 --- a/apps/red-ui/src/app/app.component.ts +++ b/apps/red-ui/src/app/app.component.ts @@ -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().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', + }); } } diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html index 768ce4f7a..f7d745275 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html @@ -2,7 +2,12 @@
{{ item.key }}
- + {{ stored.email }} diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts index 58e50858f..dce7ac47b 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts @@ -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 {