I’m using express, express-session and socket.io for part of my web application.
Is there a way to automatically get the session avaliable via socket.request.session
to update, without having to call socket.request.session.reload()
?
My middleware is as follows:
const sessionmiddleware = session(
{
secret: crypto.randomBytes(32).toString("hex"),
resave: true,
saveUninitialized: true
}
)
io.engine.use(sessionmiddleware, {
autoSave: true
});
Socket.io instance
io.on("connection", (socket) => {
const session = sockets.anysocketconnection(socket, 3);
socket.on("disconnecting", ()=>{
sockets.anysocketdisconnection(socket.request.session.reload(), socket, 3);
})
});
Note: sockets.anysocketdisconnection
currently only runs session.save(), where session is the first parameter.
Note: sockets.anysocketconnection
can be assumed that the socket returns a valid express-session from socket.request.session
.
I tried just passing the socket.request.session
or session
constant through the disconnect function. Neither of these would have the reflected changes that were updated through the running of the program (such as a POST request)
This would cause users to either be only logged in or out, with no option to change it