Skip to content

Commit

Permalink
remove oidc query params after login
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmattig committed Dec 12, 2024
1 parent 75668c8 commit ed6e4b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 8 additions & 1 deletion projects/manager/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true, onSameUrlNavigation: 'reload', bindToComponentInputs: true})],
imports: [
RouterModule.forRoot(routes, {
useHash: true,
initialNavigation: 'disabled', // navigation is enabled in app component after removing query params before the hash
onSameUrlNavigation: 'reload', // for reload the page and checking if the user is logged in again
bindToComponentInputs: true,
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
21 changes: 18 additions & 3 deletions projects/manager/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {OnInit} from '@angular/core';
import {Component, ViewContainerRef} from '@angular/core';
import {Component} from '@angular/core';
import {Router} from '@angular/router';
import {Location} from '@angular/common';
import {UserService} from '@geoengine/common';
import {firstValueFrom} from 'rxjs';

@Component({
selector: 'geoengine-root',
Expand All @@ -9,11 +12,23 @@ import {Router} from '@angular/router';
})
export class AppComponent implements OnInit {
constructor(
private readonly vcRef: ViewContainerRef,
private readonly router: Router,
private readonly location: Location,
private readonly userService: UserService,
) {}

ngOnInit(): void {
async ngOnInit(): Promise<void> {
// wait for login to be completed before initializing the router
await firstValueFrom(this.userService.getSessionOrUndefinedStream());

if (window.location.search.length > 0) {
// remove the query parameters before the hash from the url because they are not part of the app and cannot be removed later on
// services can get the original query parameters from the `URLSearchParams` in their constructor which is called before the routing is initialized.
const search = window.location.search;
window.history.replaceState(null, '', window.location.pathname);
this.location.go('/', search);
}

this.router.initialNavigation();
}
}

0 comments on commit ed6e4b9

Please sign in to comment.