[SECARSP-110][SECARSP-112] Registration/login/logout components are implemented
[platform/core/security/suspicious-activity-monitor.git] / dashboard / src / app / @core / auth / auth-guard.service.ts
1 import { Injectable } from '@angular/core';
2 import { CanActivate, Router } from '@angular/router';
3 import { NbAuthService } from '@nebular/auth';
4 import { tap } from 'rxjs/operators/tap';
5
6 @Injectable()
7 export class AuthGuardService implements CanActivate {
8
9   constructor(private authService: NbAuthService, private router: Router) { }
10
11   canActivate() {
12     return this.authService.isAuthenticated()
13       .pipe(
14       tap(authenticated => {
15         if (!authenticated) {
16           this.router.navigate(['auth/login']);
17         }
18       }),
19     );
20   }
21 }