aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing/login-guard.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/routing/login-guard.service.ts')
-rw-r--r--client/src/app/core/routing/login-guard.service.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/client/src/app/core/routing/login-guard.service.ts b/client/src/app/core/routing/login-guard.service.ts
new file mode 100644
index 000000000..18bc41ca6
--- /dev/null
+++ b/client/src/app/core/routing/login-guard.service.ts
@@ -0,0 +1,30 @@
1import { Injectable } from '@angular/core'
2import {
3 ActivatedRouteSnapshot,
4 CanActivateChild,
5 RouterStateSnapshot,
6 CanActivate,
7 Router
8} from '@angular/router'
9
10import { AuthService } from '../auth/auth.service'
11
12@Injectable()
13export class LoginGuard implements CanActivate, CanActivateChild {
14
15 constructor (
16 private router: Router,
17 private auth: AuthService
18 ) {}
19
20 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
21 if (this.auth.isLoggedIn() === true) return true
22
23 this.router.navigate([ '/login' ])
24 return false
25 }
26
27 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
28 return this.canActivate(route, state)
29 }
30}