diff --git a/CHANGELOG.md b/CHANGELOG.md index 92ff58045..2bf374e8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md). - Added live update when deactivating/reactivating users ([#287](https://github.com/sovity/authority-portal/issues/287)) - Fixed Website title not updating in some scenarios [#237](https://github.com/sovity/authority-portal/issues/237) - Fixed security vulnerabilities +- Fixed the user not being redirected to the correct URL after login ([#324](https://github.com/sovity/authority-portal/issues/324)) ### Known issues diff --git a/authority-portal-frontend/src/app/app-routing.module.ts b/authority-portal-frontend/src/app/app-routing.module.ts index 896c6a79d..f62e1ba12 100644 --- a/authority-portal-frontend/src/app/app-routing.module.ts +++ b/authority-portal-frontend/src/app/app-routing.module.ts @@ -74,17 +74,6 @@ export const LOADING_ROUTES: Routes = [ }, ]; -export const FEATURE_HOME_ROUTE: Routes = [ - { - path: 'home', - component: HomePageComponent, - data: { - requiresRole: ['USER'] satisfies UserRoleDto[], - }, - canActivate: [requiresRole], - }, -]; - const REDIRECT_TO_HOME: string[] = [ '', 'registration/pending', @@ -94,7 +83,6 @@ const REDIRECT_TO_HOME: string[] = [ const getProperRedirectUrl = (fallbackUrl: string) => { const url = localStorage.getItem('originalUrl') || fallbackUrl; - localStorage.removeItem('originalUrl'); return url; }; @@ -110,6 +98,17 @@ export const HOME_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({ pathMatch: 'full', })); +export const FEATURE_HOME_ROUTE: Routes = [ + { + path: 'home', + component: HomePageComponent, + data: { + requiresRole: ['USER'] satisfies UserRoleDto[], + }, + canActivate: [requiresRole], + }, +]; + export const FEATURE_DASHBOARD_ROUTE: Routes = [ { path: 'dashboard', diff --git a/authority-portal-frontend/src/app/core/global-state/global-state-impl.ts b/authority-portal-frontend/src/app/core/global-state/global-state-impl.ts index 70e075c4a..824ad2592 100644 --- a/authority-portal-frontend/src/app/core/global-state/global-state-impl.ts +++ b/authority-portal-frontend/src/app/core/global-state/global-state-impl.ts @@ -34,6 +34,7 @@ import { } from './global-state-actions'; import {AuthorityPortalPageSet} from './routes/authority-portal-page-set'; import {RouteConfigService} from './routes/route-config-service'; +import {UrlBeforeLoginService} from './routes/url-before-login.service'; @State({ name: 'GlobalState', @@ -46,6 +47,7 @@ export class GlobalStateImpl implements NgxsOnInit { private ngZone: NgZone, private apiService: ApiService, private routeConfigService: RouteConfigService, + private urlBeforeLoginService: UrlBeforeLoginService, ) {} ngxsOnInit(ctx: StateContext): void { @@ -123,6 +125,10 @@ export class GlobalStateImpl implements NgxsOnInit { let roles = new Set(userInfo.map((it) => it.roles).orElse([])); roles = isEqualSets(state.roles, roles) ? state.roles : roles; + if (!roles.has('UNAUTHENTICATED')) { + this.urlBeforeLoginService.clearOriginalUrl(); + } + return {userInfo, pageSet, roles}; }); } diff --git a/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts b/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts index db8ca91b7..8e02d3d19 100644 --- a/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts +++ b/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts @@ -83,21 +83,29 @@ export class RouteConfigService { } // Change routes - const routes = this.mapping[nextPageSet]; + const routes = [...this.mapping[nextPageSet]]; if (nextPageSet === 'AUTHORITY_PORTAL') { - const apRouteChildren = routes.find((r) => r.path === '')?.children; + const rootRouteIndex = routes.findIndex((r) => r.path === ''); - // Add home route depending on feature set - if (this.activeFeatureSet.isHomePageEnabled()) { - apRouteChildren?.push(...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE); - } else { - apRouteChildren?.push(...CATALOG_REDIRECTS); - } + if (rootRouteIndex !== -1) { + const rootRoute = routes[rootRouteIndex]; + const existingChildren = rootRoute.children || []; + + // Add home route depending on feature set + const newChildren = this.activeFeatureSet.isHomePageEnabled() + ? [...existingChildren, ...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE] + : [...existingChildren, ...CATALOG_REDIRECTS]; + + // Add additional routes depending on feature set & configuration + if (this.activeFeatureSet.isDashboardEnabled()) { + newChildren.push(...FEATURE_DASHBOARD_ROUTE); + } - // Add additional routes depending on feature set & configuration - if (this.activeFeatureSet.isDashboardEnabled()) { - apRouteChildren?.push(...FEATURE_DASHBOARD_ROUTE); + routes[rootRouteIndex] = { + ...rootRoute, + children: newChildren, + }; } } diff --git a/authority-portal-frontend/src/app/core/global-state/routes/url-before-login.service.ts b/authority-portal-frontend/src/app/core/global-state/routes/url-before-login.service.ts index be0ff5f3d..fef3a6f3d 100644 --- a/authority-portal-frontend/src/app/core/global-state/routes/url-before-login.service.ts +++ b/authority-portal-frontend/src/app/core/global-state/routes/url-before-login.service.ts @@ -28,14 +28,15 @@ export class UrlBeforeLoginService { }); } - public reset(): void { + public clearOriginalUrl(): void { this.originalUrl = ''; + localStorage.removeItem('originalUrl'); } public goToOriginalUrl(): void { if (this.originalUrl) { this.router.navigateByUrl(this.originalUrl); - this.reset(); + this.clearOriginalUrl(); } } } diff --git a/authority-portal-frontend/src/app/pages/home/home/home.component.ts b/authority-portal-frontend/src/app/pages/home/home/home.component.ts index a1abe49c6..83fc254d6 100644 --- a/authority-portal-frontend/src/app/pages/home/home/home.component.ts +++ b/authority-portal-frontend/src/app/pages/home/home/home.component.ts @@ -11,7 +11,7 @@ * sovity GmbH - initial implementation */ import {Component, HostBinding, Inject} from '@angular/core'; -import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser'; +import {DomSanitizer, SafeResourceUrl, Title} from '@angular/platform-browser'; import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config'; @Component({ @@ -31,7 +31,9 @@ export class HomePageComponent { constructor( @Inject(APP_CONFIG) public appConfig: AppConfig, private sanitizer: DomSanitizer, + private titleService: Title, ) { + this.titleService.setTitle('Home'); if (this.appConfig.iframeUrl) { this.iframeUrl = this.sanitizer.bypassSecurityTrustResourceUrl( this.appConfig.iframeUrl,