From e2a2d6c86c7ca39074fdff3b545947d1d58dc008 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 4 Mar 2017 11:45:47 +0100 Subject: Client: check token valitidy at startup --- client/src/app/app.component.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'client/src/app/app.component.ts') diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index f487e6c48..47d2bfdd2 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -1,14 +1,17 @@ -import { Component, ViewContainerRef } from '@angular/core'; +import { Component, OnInit, ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; import { MetaService } from 'ng2-meta'; + +import { AuthService } from './core'; +import { UserService } from './shared'; + @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.scss' ] }) - -export class AppComponent { +export class AppComponent implements OnInit { notificationOptions = { timeOut: 3000, lastOnBottom: true, @@ -25,9 +28,18 @@ export class AppComponent { constructor( private router: Router, private metaService: MetaService, + private authService: AuthService, + private userService: UserService, viewContainerRef: ViewContainerRef ) {} + ngOnInit() { + if (this.authService.isLoggedIn()) { + // The service will automatically redirect to the login page if the token is not valid anymore + this.userService.checkTokenValidity(); + } + } + isInAdmin() { return this.router.url.indexOf('/admin/') !== -1; } -- cgit v1.2.3