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
DangerZone5d 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_Selvam5d 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
DangerZone2d ago
@Sugan_Selvam Yes, but when I do this, I need req/res in order to find the auth, right?
Sugan_Selvam
Sugan_Selvam2d 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
Juraj982d 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
More Posts
Passing async data to server componentshey guys. I have a basic question - I'm fetching some "slow" data in a server component (at the pagI have been trying to get cache working with React-Query and Next.JSHello there, I'm trying to get this cache to work but I have searched far and wide and unless I'm blAnyone who knows CF Zero-Trust well?I have a homelob running proxmox, i have exposed it through a Tunnel, i have it behind Access too, iVercel server environment variables not pulling inI am currently using using [T3 Env](https://env.t3.gg/) for type safe environment variables however Shadcn Dialog + Form Error: React.Children.onlyHello, I'm want to use a From from shadcn inside a dialog from shadcn but I have this error : ErrorMost efficient monolith structure to have an Express.js REST API with Next.js SSR client?https://stackoverflow.com/questions/78670127/most-efficient-monolith-starter-project-structure-to-haView transitions aren't working with multiple elements with the same classnameHey, I have quite a unique problem and I tried searching for the solution but view transitions are rcreate t3 app breaking next-theme?????dudes and dudettes. im having a surreal issue with next theme. though if i initiated the whole app uTurbo and prisma dont work together?its weird that prisma does give errors such as `cannot convert null to object` on some stuff like crjson schema to yup raw versionI am trying to get the raw yup object with the chaining functions from a json schema. Tried some lib