From b3999b3389e1715f68159ad382dd410d3e3e8feb Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 12 Oct 2025 21:40:54 +0200 Subject: [PATCH] Prompt login dialog when user is unauthenticated during auth guard check. --- frontend/src/app/guards/auth.guard.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/guards/auth.guard.ts b/frontend/src/app/guards/auth.guard.ts index fcc3e7b..993acbf 100644 --- a/frontend/src/app/guards/auth.guard.ts +++ b/frontend/src/app/guards/auth.guard.ts @@ -1,7 +1,9 @@ import {Injectable} from '@angular/core'; import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router'; -import {Observable} from 'rxjs'; +import {map, Observable} from 'rxjs'; import {AuthService} from '@services/auth.service'; +import {MatDialog} from '@angular/material/dialog'; +import {LoginDialogComponent} from '@shared-components/login/login.component'; @Injectable({ providedIn: 'root' @@ -10,7 +12,8 @@ export class AuthGuard implements CanActivate { constructor( private authService: AuthService, - private router: Router + private router: Router, + private dialog: MatDialog ) { } @@ -19,7 +22,16 @@ export class AuthGuard implements CanActivate { state: RouterStateSnapshot ): Observable | Promise | boolean | UrlTree { if (!this.authService.checkAuthStatus()) { - return this.router.createUrlTree(['/']); + this.router.createUrlTree(['/']); + const dialogRef = this.dialog.open(LoginDialogComponent); + return dialogRef.afterClosed().pipe( + map(result => { + if (result) { + return this.router.createUrlTree([state.url]); + } + return this.router.createUrlTree(['/']); + }) + ); } const requiredAuthorizations = route.data['requiredAuthorizations'] as string[];