]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/routing/login-guard.service.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / login-guard.service.ts
1 import { Injectable } from '@angular/core'
2 import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router'
3 import { AuthService } from '../auth/auth.service'
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 }