CR1M50NC
tRPC17mo ago
3 replies
CR1M50N

How to add req to Context?

I have tried multiple variations of the inner/outer context docs code, but
ctx.req
and
ctx.res
are always undefined. https://trpc.io/docs/server/context#inner-and-outer-context.

In this related issue, Julius stated that the code shouldn't even work. https://github.com/trpc/trpc/issues/5344.

What is the official consensus on this? If it doesn't work then how else does one add the request to context (and why is it in the docs).
GitHub
🧙‍♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - Issues · trpc/trpc
Issues · trpc/trpc
Your context holds data that all of your tRPC procedures will have access to, and is a great place to put things like database connections or authentication information.
Context | tRPC
Solution
I believe the issue was because I had created a trpc caller without passing the req object.
Was this page helpful?