moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
322 stars 129 forks source link

ng2-idle move on multiple tabs screen stuck #188

Open AhmerY opened 1 year ago

AhmerY commented 1 year ago

Screenshot 2023-07-07 105433

When the 15 sec countdown start for idle time I move the cursor of mouse in last sec. The screen redirect to login screen and stuck In angular 14. The URL is redirect to login but it stuck on Home page.

import { Component, OnInit } from '@angular/core'; import { Idle, DEFAULT_INTERRUPTSOURCES } from 'ngx-idle'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({ selector: 'app-my-component', template: `

` }) export class MyComponent implements OnInit { constructor(private idle: Idle, private modalService: NgbModal) {}

ngOnInit() { // Set the idle timeout duration (in seconds) this.idle.setIdle(600); // 10 minutes

// Set the timeout duration (in seconds)
this.idle.setTimeout(15); // Disabled

// Set the interrupt events that will reset the idle timeout
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

// Subscribe to idle timeout events
this.idle.onTimeoutWarning.subscribe((countdown) => {
  if (countdown === 1) {
    // Show the pop-up alert when the countdown reaches 1 (last minute)
    this.openAlertPopup();
  }
});

this.idle.onTimeout.subscribe(() => {
  // Perform the logout or any other necessary actions
  this.logout();
});

// Start watching for user inactivity
this.idle.watch();

}

openAlertPopup() { // Open the pop-up alert using NgbModal const modalRef = this.modalService.open(AlertPopupComponent); modalRef.componentInstance.message = 'You will be logged out due to inactivity.';

modalRef.result.then((result) => {
  if (result === 'logout') {
    this.logout();
  }
});

}

logout() { // Implement your logout logic here } }