Ali Hassan
Ali Hassan

Reputation: 607

Delete the session on browser close in nodejs

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.

Upvotes: 4

Views: 7305

Answers (2)

Ramin Darvishov
Ramin Darvishov

Reputation: 1039

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
    });
    -----
});

Upvotes: 0

rdrey
rdrey

Reputation: 9529

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

Upvotes: 4

Related Questions