0

Good afternoon. I'm working on solution to create a inactivity modal after the user sign in into the application. Per requirements of the project, I can't use any library or package to implement this task. The implementation that I have, works in the following way:

  1. The user sign in into the system. A backend validation occurs.
  2. If the sign in was successful, I emit a value to the inactivity modal component to notify that the timer should start.

This solution works fine, but I have a problem when the application reload any page. Since the event is only emitted when the user sign in into the app, now the inactivity modal counter doesn't start. I tried to emit the event also in the constructor of the app.component.ts but for some reason, the service doesn't trigger the method. Thanks for any help, I really appreciate it.

// timer.service.ts

@Output() startTimerModalEvent: EventEmitter<boolean> = new EventEmitter();

  startTimer() {
    this.startTimerModalEvent.emit(true);
  }

// inactivity-modal.component.ts

 constructor(
    private timeLeftSrv: TimeLeftService
  ) {
    timeLeftSrv.startTimerModalEvent.subscribe(res => {
      if (res) {
        this.startTemp();
      }
    });
  }
Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107
Jose R. Chacón
  • 99
  • 1
  • 12
  • 1
    You can create a flag into a storage (SessionStorage or LocalStorage). – anlijudavid Dec 23 '19 at 19:51
  • Use jwtToken to verify – Developer Dec 23 '19 at 19:57
  • 1
    You need to recreate the timer state on page reload, so store your start time on the session storage and when the app starts, check if you are logged in and if the timer state exists in the storage, if so then use that state. And make sure that on logout you clean the timer state from storage! – Carlos Angarita Dec 23 '19 at 20:33
  • Thank you guys, I appreciate the comments. Now I have a better understanding of how to implement that. – Jose R. Chacón Dec 23 '19 at 21:11

0 Answers0