]>
Commit | Line | Data |
---|---|---|
1 | import { Injectable } from '@angular/core' | |
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' | |
3 | ||
4 | import { AuthService } from '../auth/auth.service' | |
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 | } |