131.3. Notify user to log in (#16)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user