Can I alter the context in a procedure?
Is there a proper way to do this? Mutating the
opts.ctx
directly seems wrong2 Replies
I think middlewares are meant for things like this? You define your initial context types when instantiating trpc.
Then you use a middleware that appends variables to the context. You can
opts.next({ user: user })
and next middlewares/queries/mutations will the ctx.user
typed.
Is this what you're looking for?I need to keep track of a session id across the lifespan of a websocket connection to correlate messages to users, the client also keeps this in local storage to handle re-connection flows
I have this where I'm kind of shoving the uuid onto the websocket object then
But this doesn't seem like the best way to do this
like I'm just hijacking the websocket object, but I guess i need something in memory to mutate to retrieve a session id in teh create context