]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/routing/login-guard.service.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / login-guard.service.ts
CommitLineData
f47bf2e1 1import { Injectable } from '@angular/core'
276d9652 2import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router'
954605a8 3import { AuthService } from '../auth/auth.service'
f47bf2e1
C
4
5@Injectable()
6export 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}