]>
Commit | Line | Data |
---|---|---|
f47bf2e1 | 1 | import { Injectable } from '@angular/core' |
276d9652 | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' |
f47bf2e1 | 3 | |
954605a8 | 4 | import { AuthService } from '../auth/auth.service' |
f47bf2e1 C |
5 | |
6 | @Injectable() | |
7 | export class LoginGuard implements CanActivate, CanActivateChild { | |
8 | ||
9 | constructor ( | |
10 | private router: Router, | |
11 | private auth: AuthService | |
12 | ) {} | |
13 | ||
14 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
15 | if (this.auth.isLoggedIn() === true) return true | |
16 | ||
17 | this.router.navigate([ '/login' ]) | |
18 | return false | |
19 | } | |
20 | ||
21 | canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
22 | return this.canActivate(route, state) | |
23 | } | |
24 | } |