i have a requirement to auto logout users after a period of inactivity. I should prompt the user with a warning about the impending logout and if no activity ensues, or the prompt is not dismissed, the user should be logged out programmatically. This needs to work with multiple tabs open to the same web app, but there should only be one warning prompt. What I mean by this, is that if the user opens a tab to the web app, then opens another tab to the same web app, then after some period of inactivity, the warning prompt should appear in only one of the tabs (the first opened tab). I should also note that all tabs use the same session on the back end. Any ideas on how to implement this? Thanks
2 Answers
Have a look at sessionStorage
(link: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage). Each new tab or window will initialize a new session. You could store a GUID or some other unique identifier in session for each tab/page the user opens. That should provide a way for you to keep track of the windows and the order they were opened. Then you can instruct just the first (or any other for that matter) to throw the prompt.

- 1,306
- 9
- 17
-
Yep, sessionStorage + Guids was the way to go. I add/remove guids as windows are opened/closed. Then I only display the dialog in the last opened window. Thanks – Lazloman Dec 27 '17 at 21:46
Recently I had the same requirement and I found ng2-idle is one of the best solutions out there. It supports multiple tabs scenario as well. Many options to customize idle time-out including interrupt sources (keyboard, mouse move & etc).
For anyone looking for same kind of requirement I highly recommend ng2-idle library.

- 2,500
- 2
- 24
- 29