]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/routing/login-guard.service.ts
add redirect after login (#1110)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / login-guard.service.ts
CommitLineData
f47bf2e1
C
1import { Injectable } from '@angular/core'
2import {
3 ActivatedRouteSnapshot,
4 CanActivateChild,
5 RouterStateSnapshot,
6 CanActivate,
7 Router
8} from '@angular/router'
9
954605a8 10import { AuthService } from '../auth/auth.service'
f47bf2e1
C
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
ec769c89
B
23 this.auth.redirectUrl = state.url
24
f47bf2e1
C
25 this.router.navigate([ '/login' ])
26 return false
27 }
28
29 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
30 return this.canActivate(route, state)
31 }
32}