Is it okay to pass the _opt.req and _opt.res variables to createTRPCContext?

When using ssg to prefetch / fetch on the server (inside getServerSideProps), I need to pass a createContext object to the ssg:
const ssg = createProxySSGHelpers({
router: appRouter,
ctx: createTRPCContext({
req: context.req as NextApiRequest,
res: context.res as NextApiResponse,
}),
transformer: superjson,
});
const ssg = createProxySSGHelpers({
router: appRouter,
ctx: createTRPCContext({
req: context.req as NextApiRequest,
res: context.res as NextApiResponse,
}),
transformer: superjson,
});
I'm using the createTRPCContext from create T3 app. Is this okay to do? I have to pass the req and res from the context because I have a Supabase server client in the background that needs that information:
export const createTRPCContext = (_opts: CreateNextContextOptions) => {
const supabase = createServerSupabaseClient<Database>({
req: _opts.req,
res: _opts.res,
});
return createInnerTRPCContext({
supabase,
});
};
export const createTRPCContext = (_opts: CreateNextContextOptions) => {
const supabase = createServerSupabaseClient<Database>({
req: _opts.req,
res: _opts.res,
});
return createInnerTRPCContext({
supabase,
});
};
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server