diff --git a/support-portal-frontend/src/app/guard/authentication.guard.ts b/support-portal-frontend/src/app/guard/authentication.guard.ts index 804b5b1..2ea6e60 100644 --- a/support-portal-frontend/src/app/guard/authentication.guard.ts +++ b/support-portal-frontend/src/app/guard/authentication.guard.ts @@ -2,13 +2,19 @@ import {Injectable} from '@angular/core'; import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router'; import {Observable} from 'rxjs'; import {AuthenticationService} from "../service/authentication.service"; +import {NotificationService} from "../service/notification.service"; +import {NotificationType} from "../notification/notification-type"; @Injectable({ providedIn: 'root' }) export class AuthenticationGuard implements CanActivate { - constructor(private authenticationService: AuthenticationService, private router: Router) { + constructor( + private authenticationService: AuthenticationService, + private router: Router, + private notificationService: NotificationService + ) { } canActivate( @@ -18,12 +24,12 @@ export class AuthenticationGuard implements CanActivate { } private isUserLoggedIn(): boolean { - if( this.authenticationService.isUserLoggedIn()) + if (this.authenticationService.isUserLoggedIn()) return true; else { this.router.navigate(['/login']); - //todo - send notification to user + this.notificationService.notify(NotificationType.ERROR, `You need to log in to access this page`.toUpperCase()); return false; }