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

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?

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

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?)

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.

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.

Hallo @all,

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

See my question and my answer: