Creaete T3 No Req or Res in TRPC context

I am trying to integrate clerk with the trpc create context, but the createContext generated by create-3t isn't passing the req or res of the request. What can I do?
5 Replies
DangerZone
DangerZoneOP6mo ago
import "server-only";

import { headers } from "next/headers";
import { cache } from "react";

import { createCaller } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";

/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(() => {
const heads = new Headers(headers());
heads.set("x-trpc-source", "rsc");

return createTRPCContext({
headers: heads,
});
});
import "server-only";

import { headers } from "next/headers";
import { cache } from "react";

import { createCaller } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";

/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(() => {
const heads = new Headers(headers());
heads.set("x-trpc-source", "rsc");

return createTRPCContext({
headers: heads,
});
});
specifically here, there is no mention of req or res. What am I doing wrong here?
Sugan_Selvam
Sugan_Selvam6mo ago
This is the server/trpc.ts and dont modify the react.tsx & server.ts in the trpc folder. I assume you wanted the auth data inside TRPC context.
No description
DangerZone
DangerZoneOP6mo ago
@Sugan_Selvam Yes, but when I do this, I need req/res in order to find the auth, right?
Sugan_Selvam
Sugan_Selvam6mo ago
No, Thats not required anymore for the TRPC context. May i ask where you are trying to find the auth? a sample path or code stub would be helpful to answer.
Juraj98
Juraj986mo ago
@DangerZone, you're most likely importing the getAuth function instead of auth function. Use the auth function, just like @Sugan_Selvam did in their screenshot. Docs
Next.js: auth()
Access minimal authentication data for managing sessions and data fetching.
Want results from more Discord servers?
Add your server