Skip to content

Commit

Permalink
Redirect to original URL after login (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit authored Aug 12, 2024
1 parent e6a0ec4 commit b6b5a5a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Patch

- Fixed user not being redirected to the correct URL after login
- Copyable contact email and subject fields on data offer detail dialogs
- Fixed the close button on the self-hosted/CaaS connector choice page [#258](https://github.com/sovity/authority-portal/issues/258)
- Fixed Dashboard showing uptimes of over 100%
- Organization list: Data offer and connector counts now show the correct numbers according to the active environment
- Fixed provider organization ID not showing up on CaaS connectors [#206](https://github.com/sovity/authority-portal/issues/206)
Expand All @@ -36,7 +39,9 @@ Read the deployment migration notes carefully if you want to retain the portal's
If you configure the optional variables incorrectly, you might end up with an inconsistent configuration.

#### Backend

Environment variable changes:

- Renamed variables:
- `authority-portal.caas.sovity.limit-per-mdsid` to `authority-portal.caas.sovity.limit-per-organization`
- New optional configuration variables - the values assigned here are the ones you should use to retain the current behavior:
Expand All @@ -51,9 +56,11 @@ Environment variable changes:
# Enables the client to connect to the CaaS service. If you weren't provided credentials for the feature by sovity, set this to false
quarkus.oidc-client.sovity.client-enabled: true
```
#### Frontend
Environment variable changes:
- New **mandantory** configuration variables - the values assigned here are the ones you should use to retain the current behavior:
- ```yaml
# UI Branding profile
Expand Down
10 changes: 8 additions & 2 deletions authority-portal-frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ const REDIRECT_TO_HOME: string[] = [
'onboard',
];

const getProperRedirectUrl = (fallbackUrl: string) => {
const url = localStorage.getItem('originalUrl') || fallbackUrl;
localStorage.removeItem('originalUrl');
return url;
};

export const CATALOG_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({
path,
redirectTo: 'catalog',
redirectTo: (() => getProperRedirectUrl('catalog'))(),
pathMatch: 'full',
}));

export const HOME_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({
path,
redirectTo: 'home',
redirectTo: (() => getProperRedirectUrl('home'))(),
pathMatch: 'full',
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '../../../app-routing.module';
import {ActiveFeatureSet} from '../../services/config/active-feature-set';
import {AuthorityPortalPageSet} from './authority-portal-page-set';
import {UrlBeforeLoginService} from './url-before-login.service';

@Injectable({providedIn: 'root'})
export class RouteConfigService {
Expand All @@ -45,6 +46,7 @@ export class RouteConfigService {

constructor(
private router: Router,
private urlBeforeLoginService: UrlBeforeLoginService,
private activeFeatureSet: ActiveFeatureSet,
) {}

Expand Down Expand Up @@ -101,7 +103,13 @@ export class RouteConfigService {
.navigateByUrl('/random-redirect-for-force-refresh', {
skipLocationChange: true,
})
.then(() => this.router.navigate([this.defaultRoute]));
.then(() => {
if (this.urlBeforeLoginService.originalUrl != '') {
this.urlBeforeLoginService.goToOriginalUrl();
} else {
this.router.navigate([this.defaultRoute]);
}
});
} else {
// Force refresh
this.forceRefreshCurrentRoute();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Injectable} from '@angular/core';
import {NavigationEnd, Router} from '@angular/router';
import {filter, first, tap} from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class UrlBeforeLoginService {
public originalUrl: string = '';

constructor(private router: Router) {
this.router.events
.pipe(
filter(
(event): event is NavigationEnd =>
event instanceof NavigationEnd &&
event.url != null &&
event.url != undefined &&
event.url != '' &&
event.url != '/' &&
event.url != '/random-redirect-for-force-refresh',
),
first(),
)
.subscribe((event) => {
this.originalUrl = event.urlAfterRedirects || event.url;
localStorage.setItem('originalUrl', this.originalUrl);
});
}

public reset(): void {
this.originalUrl = '';
}

public goToOriginalUrl(): void {
if (this.originalUrl) {
this.router.navigateByUrl(this.originalUrl);
this.reset();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
private openDataOfferDetailDialogOnceFromUrl() {
const params = this.route.firstChild?.snapshot.params;
if (params) {
console.log('PARAMS ' + params['connectorId'] + ' ' + params['assetId']);
this.openDataOfferDialog(params['assetId'], params['connectorId']);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {RouterModule} from '@angular/router';
import {UrlBeforeLoginService} from 'src/app/core/global-state/routes/url-before-login.service';
import {SharedModule} from 'src/app/shared/shared.module';
import {UnauthenticatedPageComponent} from './unauthenticated-page/unauthenticated-page.component';

Expand All @@ -34,5 +35,6 @@ import {UnauthenticatedPageComponent} from './unauthenticated-page/unauthenticat
],
declarations: [UnauthenticatedPageComponent],
exports: [UnauthenticatedPageComponent],
providers: [UrlBeforeLoginService],
})
export class UnauthenticatedPageModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, Inject} from '@angular/core';
import {UrlBeforeLoginService} from 'src/app/core/global-state/routes/url-before-login.service';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';

@Component({
Expand Down

0 comments on commit b6b5a5a

Please sign in to comment.