Creating inner context for AWS Lambda Context Options
Hi All,
I have been using tRPC for many routes, and I have started to realize I need to call certain routes on the server-side (lambda / serverless in my case), and so I was trying to follow the documentation on how to create an inner context / outer context so I can call my tRPC routes from other routes, but I am stuck and I am confused on how to go about doing it for AWS lambda context as the documentation example is rather simple.
This is what I have so far:
3 Replies
It seems that I somehow need to tell all my exising code that a user will exist if called from the API, but not for internal calls, I am confused on how this is solved with the example online: https://trpc.io/docs/server/context#inner-and-outer-context
All they do is:
And I did something similar, but since we are defining
export type Context = inferAsyncReturnType<typeof createContextInner>;
, I don't see how it ever knows about the req
and res
, and thus there are errors everywhereIf your goal is to tell if a user is present or not, you should do this through middleware.
Here are the docs you want for this probabily
https://trpc.io/docs/server/server-side-calls
Server Side Calls | tRPC
You may need to call your procedure(s) directly from the same server they're hosted in, router.createCaller() can be used to achieve this.
Also I dont think you should call one route from another. You should abstract out whatever logic you want to call into a separate function and call it directly from the server