source: trip-planner-front/src/app/auth/auth.guard.ts

Last change on this file was 84d0fbb, checked in by Ema <ema_spirova@…>, 3 years ago

spring security 2.0

  • Property mode set to 100644
File size: 552 bytes
Line 
1import { Injectable } from '@angular/core';
2import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
3import { Observable } from 'rxjs';
4
5@Injectable({
6 providedIn: 'root'
7})
8export class AuthGuard implements CanActivate {
9
10 constructor(private router : Router){}
11 canActivate(
12 route: ActivatedRouteSnapshot,
13 state: RouterStateSnapshot): boolean{
14
15 if(localStorage.getItem('token') != null)
16 return true;
17 this.router.navigate(['planners']);
18 return false;
19 }
20
21}
Note: See TracBrowser for help on using the repository browser.