]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.component.ts
Client: check token valitidy at startup
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
1 import { Component, OnInit, ViewContainerRef } from '@angular/core';
2 import { Router } from '@angular/router';
3
4 import { MetaService } from 'ng2-meta';
5
6 import { AuthService } from './core';
7 import { UserService } from './shared';
8
9 @Component({
10 selector: 'my-app',
11 templateUrl: './app.component.html',
12 styleUrls: [ './app.component.scss' ]
13 })
14 export class AppComponent implements OnInit {
15 notificationOptions = {
16 timeOut: 3000,
17 lastOnBottom: true,
18 clickToClose: true,
19 maxLength: 0,
20 maxStack: 7,
21 showProgressBar: false,
22 pauseOnHover: false,
23 preventDuplicates: false,
24 preventLastDuplicates: 'visible',
25 rtl: false
26 };
27
28 constructor(
29 private router: Router,
30 private metaService: MetaService,
31 private authService: AuthService,
32 private userService: UserService,
33 viewContainerRef: ViewContainerRef
34 ) {}
35
36 ngOnInit() {
37 if (this.authService.isLoggedIn()) {
38 // The service will automatically redirect to the login page if the token is not valid anymore
39 this.userService.checkTokenValidity();
40 }
41 }
42
43 isInAdmin() {
44 return this.router.url.indexOf('/admin/') !== -1;
45 }
46 }