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[];