Browse Source

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
pull/16860/head
Maksym Tsymbarov 3 days ago
committed by GitHub
parent
commit
9d8eb80e2f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 39
      ui-ngx/src/app/core/auth/auth.service.ts
  2. 1
      ui-ngx/src/app/shared/components/user-menu.component.ts

39
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<AuthPayload> {
const authUser = getCurrentAuthUser(this.store);
if (!authUser) {

1
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();
}

Loading…
Cancel
Save