ducktors/fastify-socket.io

get session data?

Closed this issue ยท 5 comments

hi,
when using both fastify-socket.io and fastify-session, is there a way to get session data when socket client connects?
something like this would be cool:
image

solved! here is the code I used:

    app.io.on('connect', (socket) => {
        console.info('socket connected:',socket.id);
        let sid = app.parseCookie(socket.handshake.headers.cookie).sessionId;
        let req = {};
        app.decryptSession(sid, req, () => {
            console.log(req.session)
            // You can basically access req.session here
        });
    })
})

@korobaka thanks for sharing the solution!

@korobaka thanks for sharing the solution!

no problem! it would be cool to include directly socket.session in this module :)

feel free to open a PR, I'll be more than happy to review ๐Ÿ˜„

feel free to open a PR, I'll be more than happy to review ๐Ÿ˜„

I'll try to do this today :)