MrJohz
Explore posts from serversHow can I access the session in fastify when using `useWSS: true`?
Hi @Mr. Joker, I ended up writing my solution up on my blog, you can read that here: https://jonathan-frere.com/posts/trpc-fastify-websockets/
Specifically, the solution I found was this:
7 replies
How can I access the session in fastify when using `useWSS: true`?
I did. Basically, the type of
req
is wrong: for websockets, it's FastifyRequest | IncomingMessage
where IncomingMessage
is the raw node request object. To get hold of the FastifyRequest
object, you can use a Fastify to listen to all incoming requests, and then save those requests in a WeakMap. Then in the context you can use the WeakMap to fetch the original requests out again.
I'll write it up properly tomorrow.7 replies