4

It is possible to delete the session in node js when the browser closes?

I want to have the check that if the user did not select the keep me login checkbox and then closes the window. He should asked to re login.

Ali Hassan
  • 587
  • 1
  • 9
  • 24

2 Answers2

4

That's a cookie-specific setting: If you store the session data in a session-only cookie, it will disappear when the browser closes.

See this answer to make a browser-session cookie with express: Node.js/Express.js session management cookie to be session cookie

Community
  • 1
  • 1
rdrey
  • 8,971
  • 3
  • 38
  • 50
0

You can write your own session delete function on event 'disconnect'

socketServer.sockets.on('connection', function onSocket(client) {
    client.on('disconnect', function() {
        console.log("disconnect");
        // some code
    });
    -----
});
Ramin Darvishov
  • 1,022
  • 1
  • 14
  • 25
  • While this is a potentially useful solution, this is not portable, as not all browsers support websockets. Using cookie settings would be preferable, hence I gave you a -1. – Kenny Worden Apr 22 '17 at 20:46