From 9d8eb80e2fb271f8558f693b5ad246bd9cfc6396 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Tue, 1 Dec 2026 16:54:51 +0100 Subject: [PATCH] Fixed deep links being replaced by the default dashboard after login (#16835) * Fixed deep links being replaced by the default dashboard after login * PR comments fixes * Fixed PR comments * Fixed PR comments --- ui-ngx/src/app/core/auth/auth.service.ts | 39 +++++++++++-------- .../shared/components/user-menu.component.ts | 1 + 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index edd852247c..1c4c57431e 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -10,7 +10,7 @@ import { catchError, map, mergeMap, tap } from 'rxjs/operators'; import { setEdqsEnabled, setNullsOrderStrategy } from '@shared/models/page/page-link'; import { LoginRequest, LoginResponse, PublicLoginRequest } from '@shared/models/login.models'; -import { Router, UrlTree } from '@angular/router'; +import { PRIMARY_OUTLET, Router, UrlTree } from '@angular/router'; import { defaultHttpOptions, defaultHttpOptionsFromConfig, RequestConfig } from '../http/http-utils'; import { UserService } from '../http/user.service'; import { Store } from '@ngrx/store'; @@ -281,24 +281,12 @@ export class AuthService { } else if (authState.authUser.authority === Authority.MFA_CONFIGURATION_TOKEN) { result = this.router.parseUrl('login/force-mfa'); } else if (!path || path === 'login' || this.forceDefaultPlace(authState, path, params)) { - if (this.redirectUrl) { - const redirectUrl = this.redirectUrl; - this.redirectUrl = null; + const redirectUrl = this.redirectUrl; + this.redirectUrl = null; + if (redirectUrl && !authState.authUser.isPublic && this.isDeepLink(redirectUrl)) { result = this.router.parseUrl(redirectUrl); } else { - result = this.router.parseUrl('home'); - } - if (authState.authUser.authority === Authority.TENANT_ADMIN || authState.authUser.authority === Authority.CUSTOMER_USER) { - if (this.userHasDefaultDashboard(authState)) { - const dashboardId = authState.userDetails.additionalInfo.defaultDashboardId; - if (authState.forceFullscreen) { - result = this.router.parseUrl(`dashboard/${dashboardId}`); - } else { - result = this.router.parseUrl(`dashboards/${dashboardId}`); - } - } else if (authState.authUser.isPublic && authState.lastPublicDashboardId) { - result = this.router.parseUrl(`dashboard/${authState.lastPublicDashboardId}`); - } + result = this.defaultPlaceUrl(authState); } } } else { @@ -339,6 +327,23 @@ export class AuthService { })); } + private defaultPlaceUrl(authState: AuthState): UrlTree { + if (authState.authUser.authority === Authority.TENANT_ADMIN || authState.authUser.authority === Authority.CUSTOMER_USER) { + if (this.userHasDefaultDashboard(authState)) { + const dashboardId = authState.userDetails.additionalInfo.defaultDashboardId; + return this.router.parseUrl(authState.forceFullscreen ? `dashboard/${dashboardId}` : `dashboards/${dashboardId}`); + } else if (authState.authUser.isPublic && authState.lastPublicDashboardId) { + return this.router.parseUrl(`dashboard/${authState.lastPublicDashboardId}`); + } + } + return this.router.parseUrl('home'); + } + + private isDeepLink(url: string): boolean { + const segments = this.router.parseUrl(url).root.children[PRIMARY_OUTLET]?.segments.map(segment => segment.path) ?? []; + return segments.length > 0 && segments[0] !== 'login' && !(segments.length === 1 && segments[0] === 'home'); + } + private loadUser(doTokenRefresh): Observable { const authUser = getCurrentAuthUser(this.store); if (!authUser) { diff --git a/ui-ngx/src/app/shared/components/user-menu.component.ts b/ui-ngx/src/app/shared/components/user-menu.component.ts index ea54513909..ee32752b56 100644 --- a/ui-ngx/src/app/shared/components/user-menu.component.ts +++ b/ui-ngx/src/app/shared/components/user-menu.component.ts @@ -136,6 +136,7 @@ export class UserMenuComponent { logout(): void { this.menuClicked.emit(); + this.authService.redirectUrl = null; this.authService.logout(); }