tRPCttRPC
Powered by
SimoAmiS
tRPC•15mo ago•
1 reply
SimoAmi

Context parameters in server side calls

Hello, I using trpc 11.0.0-rc.633 and Next.js 15.0.3 and have the following questions:
1. when a
createContext()
createContext()
function is defined with the
FetchCreateContextFnOptions
FetchCreateContextFnOptions
parameter signature, how do you fill that information out when using server side api calls, for example via
createCaller
createCaller
? The example in the docs is inaccurate in that it defines a
createContext
createContext
function to require some parameters:
export const createContext = async (opts: CreateNextContextOptions) => { ... }
export const createContext = async (opts: CreateNextContextOptions) => { ... }

and then runs it without passing any parameters:
const caller = createCaller(await createContext());
const caller = createCaller(await createContext());

2. My context needs access to the requesting url query string to get a token (used for shared links). How do I get the url or query parameters in a server call where I don't have implicit access to the request object?
3. In the Next.js main layout, where a
<RootLayout />
<RootLayout />
is defined, I need to fetch the current user to pass it along to react components. I have a
getUser()
getUser()
procedure for this. Do I use the client side api defined with
createTRPCReact
createTRPCReact
to call the procedure? or can I use the server side api created with a
createCaller
createCaller
since I assume the root layout will be rendered on the server side?
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.
Context | tRPC
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Duplicated tRPC server-side calls
PavidR 🐈🐈PPavidR 🐈🐈 / ❓-help
2y ago
Make server side tRPC calls on an external tRPC server ?
PavidR 🐈🐈PPavidR 🐈🐈 / ❓-help
15mo ago
Type error when creating a server-side context 🤔
JackJJack / ❓-help
2y ago