When I use both fastify-websocket and fastify-session in my Fastify app, I run into an issue.
fastify.get( myWebsocketPath, websocket: true },
async (connection, rawRequest) => {
console.log(`request for websocket connection`)
if( request.session.authenticated ) {
myApi( connection.socket )
}
})
Except this fails because I only have the rawRequest, not the regular request decorated with the session.
It seems that to get an external handle for it you need to set the session store yourself. It's better to use a custom store, but for simplicity in this example I will use the built-in one provided by
fastify-session
.Credit to Zekth for pointing me in the right direction.