yourlabs / django-session-security

A little javascript and middleware work together to ensure that the user was active during the past X minutes in any tab he has open. Otherwise, display a warning leaving a couple of minutes to show any kind of activity like moving the mouse. Otherwise, logout the user.
http://django-session-security.rtfd.org
MIT License
310 stars 141 forks source link

Option to end session on tab close #121

Open as3445 opened 5 years ago

as3445 commented 5 years ago

One of the requirements for a project that I am working on is that the session would expire on tab close. I can imagine other may want a similar feature. I propose that this app implement an endpoint that the client can call .onbeforeunload() and the server will invalidate the session.

claytondaley commented 5 years ago

Django has built-in support for this.

as3445 commented 5 years ago

That will not work if I just close my tab without closing the window.

I have been looking up how I might do this, and actually there's no easy way to differentiate navigation to a new page vs closing the tab. 🤔 So .onbeforeunload() is actually not viable