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
Issues · trpc/trpc
🧙♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - Issues · trpc/trpc
Context | 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.
Solution:Jump to solution
I believe the issue was because I had created a trpc caller without passing the req object.
1 Reply
Solution
I believe the issue was because I had created a trpc caller without passing the req object.