How to logout the user when he closes the browser or PC crashes


#1

We are evaluating Meteor for building an application, and it’s awesome!

I see that meteor remembers the user across browser restarts. But, we would have liked to make it optional, by providing a “remember-me” check box instead. Browsing for a solution, I came across suggestions to catch the close event and logout the user programmatically. But what happens if the browser hangs, or the PC crashes, was my concern.

How to handle this scenario?


#2

You can add this package to address that situation. https://atmospherejs.com/zuuk/stale-session


#3

Thanks for the link. How would it behave if the browser crashes, the user leaves, and another user reopens the browser before the timeout occurs? (Or another user tries to hack the local-storage?)


#4

I guess You can call meteor Meteor.logout(); during meteor.startup on the client. The bad side if a user refreshes his browser it will automatically logout as user as well. I haven’t tested it yet but should work.

Maybe others has other way to address it.


#5

You can’t simply detect crashes, you could use mizzao:user-status to track online presence and removing resume.loginTokens on the server when the user status changes to offline (you’ll need peerlibrary:server-autorun), or the stale-session package sounds promising. On the other hand, you could very simply detect browser/tab close with window.onbeforeunload or window.onunload and as you said, logout the user programmatically.


#6

Hallo @all,

ist there a way to detect when the user close the browser, not the tab or reload the page?


#7

See my question and my answer: