Elffuss BraidHub

kikocis/dataspace-portal public

fix: redirect the user to the original Url after login (#382)

Changeset0851d8a418d861427d11accf2dc65abfd9ce75a111bf5aba1f55e5a7036d267c
AuthorIlia Orlov <66363651+illfixit@users.noreply.github.com> · 2024-11-28 17:48 +01:00
CommitterGitHub <noreply@github.com> · 2024-11-28 17:48 +01:00
Parents23938f4a7f5e

Browse the files at this changeset

6 files changed

modified CHANGELOG.md +1 −0
@@ -26,6 +26,7 @@
2626 - Added live update when deactivating/reactivating users ([#287](https://github.com/sovity/authority-portal/issues/287))
2727 - Fixed Website title not updating in some scenarios [#237](https://github.com/sovity/authority-portal/issues/237)
2828 - Fixed security vulnerabilities
29+- Fixed the user not being redirected to the correct URL after login ([#324](https://github.com/sovity/authority-portal/issues/324))
2930
3031 ### Known issues
3132
modified authority-portal-frontend/src/app/app-routing.module.ts +11 −12
@@ -74,17 +74,6 @@
7474 },
7575 ];
7676
77-export const FEATURE_HOME_ROUTE: Routes = [
78- {
79- path: 'home',
80- component: HomePageComponent,
81- data: {
82- requiresRole: ['USER'] satisfies UserRoleDto[],
83- },
84- canActivate: [requiresRole],
85- },
86-];
87-
8877 const REDIRECT_TO_HOME: string[] = [
8978 '',
9079 'registration/pending',
@@ -94,7 +83,6 @@
9483
9584 const getProperRedirectUrl = (fallbackUrl: string) => {
9685 const url = localStorage.getItem('originalUrl') || fallbackUrl;
97- localStorage.removeItem('originalUrl');
9886 return url;
9987 };
10088
@@ -110,6 +98,17 @@
11098 pathMatch: 'full',
11199 }));
112100
101+export const FEATURE_HOME_ROUTE: Routes = [
102+ {
103+ path: 'home',
104+ component: HomePageComponent,
105+ data: {
106+ requiresRole: ['USER'] satisfies UserRoleDto[],
107+ },
108+ canActivate: [requiresRole],
109+ },
110+];
111+
113112 export const FEATURE_DASHBOARD_ROUTE: Routes = [
114113 {
115114 path: 'dashboard',
modified authority-portal-frontend/src/app/core/global-state/global-state-impl.ts +6 −0
@@ -34,6 +34,7 @@
3434 } from './global-state-actions';
3535 import {AuthorityPortalPageSet} from './routes/authority-portal-page-set';
3636 import {RouteConfigService} from './routes/route-config-service';
37+import {UrlBeforeLoginService} from './routes/url-before-login.service';
3738
3839 @State<GlobalState>({
3940 name: 'GlobalState',
@@ -46,6 +47,7 @@
4647 private ngZone: NgZone,
4748 private apiService: ApiService,
4849 private routeConfigService: RouteConfigService,
50+ private urlBeforeLoginService: UrlBeforeLoginService,
4951 ) {}
5052
5153 ngxsOnInit(ctx: StateContext<any>): void {
@@ -123,6 +125,10 @@
123125 let roles = new Set(userInfo.map((it) => it.roles).orElse([]));
124126 roles = isEqualSets(state.roles, roles) ? state.roles : roles;
125127
128+ if (!roles.has('UNAUTHENTICATED')) {
129+ this.urlBeforeLoginService.clearOriginalUrl();
130+ }
131+
126132 return {userInfo, pageSet, roles};
127133 });
128134 }
modified authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts +21 −13
@@ -83,21 +83,29 @@
8383 }
8484
8585 // Change routes
86- const routes = this.mapping[nextPageSet];
86+ const routes = [...this.mapping[nextPageSet]];
8787
8888 if (nextPageSet === 'AUTHORITY_PORTAL') {
89- const apRouteChildren = routes.find((r) => r.path === '')?.children;
90-
91- // Add home route depending on feature set
92- if (this.activeFeatureSet.isHomePageEnabled()) {
93- apRouteChildren?.push(...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE);
94- } else {
95- apRouteChildren?.push(...CATALOG_REDIRECTS);
96- }
97-
98- // Add additional routes depending on feature set & configuration
99- if (this.activeFeatureSet.isDashboardEnabled()) {
100- apRouteChildren?.push(...FEATURE_DASHBOARD_ROUTE);
89+ const rootRouteIndex = routes.findIndex((r) => r.path === '');
90+
91+ if (rootRouteIndex !== -1) {
92+ const rootRoute = routes[rootRouteIndex];
93+ const existingChildren = rootRoute.children || [];
94+
95+ // Add home route depending on feature set
96+ const newChildren = this.activeFeatureSet.isHomePageEnabled()
97+ ? [...existingChildren, ...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE]
98+ : [...existingChildren, ...CATALOG_REDIRECTS];
99+
100+ // Add additional routes depending on feature set & configuration
101+ if (this.activeFeatureSet.isDashboardEnabled()) {
102+ newChildren.push(...FEATURE_DASHBOARD_ROUTE);
103+ }
104+
105+ routes[rootRouteIndex] = {
106+ ...rootRoute,
107+ children: newChildren,
108+ };
101109 }
102110 }
103111
modified authority-portal-frontend/src/app/core/global-state/routes/url-before-login.service.ts +3 −2
@@ -28,14 +28,15 @@
2828 });
2929 }
3030
31- public reset(): void {
31+ public clearOriginalUrl(): void {
3232 this.originalUrl = '';
33+ localStorage.removeItem('originalUrl');
3334 }
3435
3536 public goToOriginalUrl(): void {
3637 if (this.originalUrl) {
3738 this.router.navigateByUrl(this.originalUrl);
38- this.reset();
39+ this.clearOriginalUrl();
3940 }
4041 }
4142 }
modified authority-portal-frontend/src/app/pages/home/home/home.component.ts +3 −1
@@ -11,7 +11,7 @@
1111 * sovity GmbH - initial implementation
1212 */
1313 import {Component, HostBinding, Inject} from '@angular/core';
14-import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
14+import {DomSanitizer, SafeResourceUrl, Title} from '@angular/platform-browser';
1515 import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
1616
1717 @Component({
@@ -31,7 +31,9 @@
3131 constructor(
3232 @Inject(APP_CONFIG) public appConfig: AppConfig,
3333 private sanitizer: DomSanitizer,
34+ private titleService: Title,
3435 ) {
36+ this.titleService.setTitle('Home');
3537 if (this.appConfig.iframeUrl) {
3638 this.iframeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
3739 this.appConfig.iframeUrl,