tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

Cannot set headers in procedures with fetch adapter

Am i right that with such a setup in nextjs app router route handler: ```ts const handler = async (request: NextRequest) => { const response = await fetchRequestHandler({... request ...}) return response...

Does anybody now how to fix cors policy error?

I am facing this error: Access to fetch at 'http://localhost:3002/trpc/getBotTag?batch=1&input=%7B%7D' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. But this is only happening on "use client" components....
No description

how to handle error from Zod in trpc?

I would like to return error instead throwing it away so i could show user nice feedback i found https://zod.dev/?id=safeparse but i dont know how to implement it ...

404 TRPCError: no query procedure on path

Hi, this is my entire standalone tRPC server:```ts import { initTRPC } from "@trpc/server"; import { createHTTPServer } from "@trpc/server/adapters/standalone"; import cors from "cors"; ...

Call multiple TRPC endpoints from onSuccess()?

I would like to create an API chain for analysing a geographic area where one successful API call can lead to multiple new API's being called to render the components in the right orders for the user. This works really well for single API calls, but when combining multiple of them together to be triggered at a onSuccess() call, the trpc combines them all together instead of taking them one by one. Does anyone know how to solve this?...
No description

How to set sizeLimit > 1MB (to solve 413 error)?

Hi all, I am trying out the T3 stack where I want to send area polygons given by the user to my NextJs backend using TRPC. It worked well for smaller polygons drawn by hand, but one I allowed my users to upload files over 1MB I run into the problem of '413 (Body exceeded 1mb limit)' I found in the NextJs documentation:...
No description

How to manage server to server communication

Would managing headers this way work in nextjs as server to server communication? or does next manage multiple requests in parallel so there is the possibility it will send the token from one user to another user? Do I have another way of using TRPC from the server side of next if the TRPC server is hosted in other place?...
No description

Replacing the dot notation in URLs with forward slash `/` ?

is there a way to replace the dot separation with a forward slash instead ?
so instead of /api/trpc/post.byId it would be /api/trpc/post/byId...

Which one method should I use for creating trpc for server componetns in Nextjs 13 App dir

Hi which one I should use experimental_createTRPCNextAppDirServer or createTRPCProxyClient when it comes to defining trpc api for the server components? I mean both works fine with next13 app dir and im confused

Can someone explain to me the use of tRPC in server components?

I can really see the need for tRPC in client components but can someone explain to me how you would go about it in server components? In server components I can directly retrieve data from my database with Drizzle or Prisma. If I'll use tRPC in the server component will it just make a request to the server where it already is at that moment through the API or is tRPC able to handle this and run the code without making an extra call?...

Error-Boundary and TRPC

Is there a nice way to catch errors from TRPC at a global level and bubble them into a simple alert component?

Type errors in lambda integration

I really don't know where to start with this error.... I'm going to be integrating tRPC into a lambda, and I have a merged child router, but I'm getting this type error: ``` Type 'CreateRouterInner<RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { users: CreateRouterInner<...>; }>' is not assignable to type 'AnyRouter'. The types returned by 'createCaller(...)' are incompatible between these types....

Hybrid application with offline and online mode setup with tRPC

Hi, I was wondering if I could setup tRPC in way that one http link is using local API (for offline mode) and another uses online http link for when user logs in and connects to online service. What would be best setup, is it fine if I use splitLink in this case. Is tRPC ment for this kind of setup. Thanx...

query with no input reports error

i have a simple router with a list procedure that takes no input and just does a .query() it used to work, but now in the client side, when i try to call .useQuery() with no parameters i'm getting this error... ```...
No description

Next cookies() not being set on Mutation in App Dir (T3 Turbo)

Trying to set cookies inside TRPC using Nextjs App Router, using the T3 Turbo setup. Setting cookies works fine inside Queries, but cookies are not set inside Mutations. Maybe I'm doing something wrong, not very up to date with TRPC + App Dir, or it could be a bug in next, not sure. ```ts...

tRPC error in app Router (undefined headers)

I use the tRPC file structure from Jack Herringtons video I added clerk auth for protected routes and set the create Context in the route handler: ```ts createContext: () => createTRPCContext(req),...

How to serve files with trpc?

Is is possible to serve files with trpc? E.g., by creating a middleware and returning directly from the middleware? I can't seem to serve files with trpc. Should a separate server be set up just for file serving?

tRPC in Next without api rotes

Hello! I have NextJS app that gets data in gSP using some third-party client. This data comes untyped, and i'm thinking if tRPC can help me to manage this behavior in a better way, than just zod validation. One more thing - i do not want to make some public endpoint for quering this data. But I can't find any examples of tRPC usage in NextJS without API routes. Does it mean that tRPC do not fit my task as it actually "a gates of BE part"?...