Last change
on this file since 993189e was 993189e, checked in by Mile Jankuloski <mile.jankuloski@…>, 4 years ago |
Auth guards and services, refactored components
|
-
Property mode
set to
100644
|
File size:
705 bytes
|
Line | |
---|
1 | import { Injectable } from '@angular/core';
|
---|
2 | import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
|
---|
3 | import { Observable } from 'rxjs';
|
---|
4 |
|
---|
5 | import { AuthService } from './auth.service';
|
---|
6 |
|
---|
7 | @Injectable({
|
---|
8 | providedIn: 'root'
|
---|
9 | })
|
---|
10 | export 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.