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