From 26d823d48653681a724826265f2c2d429522f3f7 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 17 Sep 2021 15:38:46 +0300 Subject: [PATCH] 131.3. Notify user to log in (#16) --- .../src/app/guard/authentication.guard.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; }