]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/routing/login-guard.service.ts
Refactor login redirection/button links
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / login-guard.service.ts
CommitLineData
f47bf2e1 1import { Injectable } from '@angular/core'
98bd5e22 2import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router'
954605a8 3import { AuthService } from '../auth/auth.service'
98bd5e22 4import { RedirectService } from './redirect.service'
f47bf2e1
C
5
6@Injectable()
7export 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}