Context is not fully globally accessed? [ probably newbie question ]
I create a context in the based procedure, but It's undefined in the procedure based on it.
Also the NVM I should've defined it upon server creation.
Context defined by a procedure cannot be seen by another procedure?? how do I get around that?
opts.ctx
doesn't exist before I create it, although I've used .context()
upon initializing trpc
, but that's no big deal.4 Replies
you should define the ctx variable by passing it as an argument to the opts.next() function you are returning
like this:
otherwise even though you are doing
opts.ctx = ...
, that does nothingYou can see more about how context extension works here -> https://trpc.io/docs/server/middlewares#context-extension
Middlewares | tRPC
You are able to add middleware(s) to a procedure with the t.procedure.use() method. The middleware(s) will wrap the invocation of the procedure and must pass through its return value.
Thanks @Lucas Thevenet, that saved my day, I guess reading the docs starting from the top is not that practical before I finish reading it.
Glad I could be of help! 👍