source: Farmatiko/ClientApp/src/app/shared/auth.guard.ts@ 993189e

Last change on this file since 993189e was 993189e, checked in by Mile Jankuloski <mile.jankuloski@…>, 3 years ago

Auth guards and services, refactored components

  • Property mode set to 100644
File size: 705 bytes
Line 
1import { Injectable } from '@angular/core';
2import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
3import { Observable } from 'rxjs';
4
5import { AuthService } from './auth.service';
6
7@Injectable({
8 providedIn: 'root'
9})
10export class AuthGuard implements CanActivate {
11 constructor(private router: Router, private authService: AuthService) {
12
13 }
14
15 canActivate(next: ActivatedRouteSnapshot,state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
16 const head = this.authService.headValue;
17 if(head) {
18 return true;
19 }
20 this.router.navigate(['/login']);
21 return false;
22 }
23
24}
Note: See TracBrowser for help on using the repository browser.