Skip to content
Snippets Groups Projects
Commit 3ecd8338 authored by kbeyro's avatar kbeyro
Browse files

Fix problem with timer after logout

parent 627aae7f
No related branches found
No related tags found
No related merge requests found
import { Component, ViewEncapsulation } from '@angular/core';
import { AppConfigService, ConfigurationService } from './service';
import {Component, ViewEncapsulation} from '@angular/core';
import {AppConfigService, ConfigurationService} from './service';
import {TranslateService} from '@ngx-translate/core';
import {AuthService} from './auth/auth.service';
import {Router} from '@angular/router';
......@@ -7,10 +7,10 @@ import {ServiceUnavailableService} from './service-unavailable/service-unavailab
import {IdleTimer} from './auth/idle-timer';
@Component({
selector: 'nmaas-root',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
encapsulation: ViewEncapsulation.None
selector: 'nmaas-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
......@@ -33,8 +33,8 @@ export class AppComponent {
this.authService.isLoggedIn$.subscribe(
isLoggedIn => {
if (isLoggedIn) {
this.timer = new IdleTimer( {
timeout: 900 , // 15 min
this.timer = new IdleTimer({
timeout: 900, // 15 min
onTimeout: () => {
this.authService.logout();
this.router.navigate(['/welcome'])
......
......@@ -44,7 +44,6 @@ export class IdleTimer {
}
private cleanUp() {
console.log('cleanup')
clearInterval(this.interval);
window.removeEventListener('mousemove', this.eventHandler);
window.removeEventListener('scroll', this.eventHandler);
......
import {Component, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import { Router } from '@angular/router';
import {Component, OnInit, ViewChild} from '@angular/core';
import {Router} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
import {interval, Subscription} from 'rxjs';
import {AuthService} from '../../auth/auth.service';
......@@ -13,9 +13,9 @@ import {DatePipe} from '@angular/common';
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit, OnChanges {
export class NavbarComponent implements OnInit {
@ViewChild(ModalNotificationSendComponent, { static: true })
@ViewChild(ModalNotificationSendComponent, {static: true})
public notificationModal;
public languages: string[];
......@@ -59,23 +59,17 @@ export class NavbarComponent implements OnInit, OnChanges {
}
}
this.intervalId = setInterval(() => {
const expiredTimeText: string = localStorage.getItem('_expiredTime')
if (parseInt(expiredTimeText, 10) > Date.now()) {
this.time = this.datePipe.transform(new Date(parseInt(expiredTimeText, 10) - Date.now()), 'mm:ss')
console.debug('Autologout in', this.time);
if (this.authService.isLogged()) {
const expiredTimeText: string = localStorage.getItem('_expiredTime')
if (parseInt(expiredTimeText, 10) > Date.now()) {
this.time = this.datePipe.transform(new Date(parseInt(expiredTimeText, 10) - Date.now()), 'mm:ss')
console.debug('Autologout in', this.time);
}
this.showClock = parseInt(expiredTimeText, 10) - Date.now() < 180000 && parseInt(expiredTimeText, 10) - Date.now() >= 0;
}
this.showClock = parseInt(expiredTimeText, 10) - Date.now() < 180000 && parseInt(expiredTimeText, 10) - Date.now() >= 0;
}, 1000);
// this.authService.isLoggedIn$.subscribe( data => {
// if (!data) {
// console.warn("state", data);
// clearInterval(this.intervalId);
// }
// })
}
ngOnChanges(changes: SimpleChanges): void {
}
public getSupportedLanguages() {
......@@ -87,9 +81,9 @@ export class NavbarComponent implements OnInit, OnChanges {
public checkUserRole(): boolean {
return this.authService.getDomains().filter(value => value != this.domainService.getGlobalDomainId()).length > 0
|| this.authService.getRoles().filter(value => value != 'ROLE_INCOMPLETE')
.filter(value => value != 'ROLE_GUEST')
.length > 0;
|| this.authService.getRoles().filter(value => value != 'ROLE_INCOMPLETE')
.filter(value => value != 'ROLE_GUEST')
.length > 0;
}
public showNotificationModal(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment