maddest
maddest
TtRPC
Created by maddest on 2/23/2024 in #❓-help
Unable to use caller, in frontend bcz i dont have access to req and res objects
i was trying to use trpc callers, for ssr the queries, but i was not able to create one since i have req and res objects in my context, where my context looks like
interface CreateInnerContextOptions
extends Partial<trpcNext.CreateNextContextOptions> {
session: Session | null;
}

export async function createContextInner(opts: CreateInnerContextOptions) {
return {
// db,
session: opts.session,
};
}

// for RSC(app router) we need to send only authOptions for getting server session
export async function createContext({
req,
res,
}: trpcNext.CreateNextContextOptions) {
const session = await getServerSession(authOptions);
// const session = null;
const contextInner = await createContextInner({ session });
return {
...contextInner,
req,
res,
};
}
interface CreateInnerContextOptions
extends Partial<trpcNext.CreateNextContextOptions> {
session: Session | null;
}

export async function createContextInner(opts: CreateInnerContextOptions) {
return {
// db,
session: opts.session,
};
}

// for RSC(app router) we need to send only authOptions for getting server session
export async function createContext({
req,
res,
}: trpcNext.CreateNextContextOptions) {
const session = await getServerSession(authOptions);
// const session = null;
const contextInner = await createContextInner({ session });
return {
...contextInner,
req,
res,
};
}
it asks me to give it req and res objects which i cannot do, to use it, is there some way through which i can use the same trpc endpoints, so that i can also use them in server components? This is my trpr Provider Wrapper
export default function TrpcProvider({ children }: PropsWithChildren) {
const [queryClient] = useState(() => new QueryClient({}));
const [trpcClient] = useState(() =>
trpc.createClient({
transformer: SuperJSON,
links: [
httpBatchLink({
url: getUrl(),
}),
],
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
}
export default function TrpcProvider({ children }: PropsWithChildren) {
const [queryClient] = useState(() => new QueryClient({}));
const [trpcClient] = useState(() =>
trpc.createClient({
transformer: SuperJSON,
links: [
httpBatchLink({
url: getUrl(),
}),
],
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
}
this is my trpc client, which i am using in client components,
import { createTRPCReact } from "@trpc/react-query";

import { type AppRouter } from "../server/routers/_app";

export const trpc = createTRPCReact<AppRouter>({});
import { createTRPCReact } from "@trpc/react-query";

import { type AppRouter } from "../server/routers/_app";

export const trpc = createTRPCReact<AppRouter>({});
3 replies
TtRPC
Created by maddest on 12/23/2023 in #❓-help
trpc openapi does not work on app router
No description
3 replies
TtRPC
Created by maddest on 12/20/2023 in #❓-help
TRPCError class, public readonly cause?: Error; this line should have override function
hey i am trying to use the TRPCError for throwing errors in my apps, but i am getting this error, changing the line from public readonly cause?: Error; to public override readonly cause?: Error; fixes the problem the problem but i am doing that in node_modules which is not how this gets resolved, how do i resolve this? when trying to use module arugmentation, i am getting an dupliate declare class error meaning the TRPCError class has already be declared in TRPCError.d.ts file please help me resolve this issue, my @trpc/server and @trpc/client version is
"@trpc/client": "^10.38.5",
"@trpc/server": "^10.38.5",
"@trpc/client": "^10.38.5",
"@trpc/server": "^10.38.5",
my typescript version is above 5 i am using turborepo, this error was not there before, but since i was doing some migration of my trpc code to a seperate trpc package, i am getting these errrors
23 replies