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