T
tRPC

External calls

External calls

ALAdrian Lysakowski8/30/2023
Hi! I am using T3 stack, tRPC together with clerk, and i need to create users within the app, being already logged in, so i need to use external API, quiestion is, what are best practices, doing external API calls inside trpc route? or do it on component side
FFaizan9/6/2023
@aidean0406 were you able to get answers somewhere ?
ALAdrian Lysakowski9/6/2023
nah but i figured it out myself
FFaizan9/6/2023
what was your conclusion ?
ALAdrian Lysakowski9/6/2023
call should be inside trpc, or anywhere on "server" side, as u will need to send them token inside request my component is client side component using trpc so there is no othey way than having it in one of trpc route it works super fine, in case of problem with request i am throwing simply 5XX error that users couldn't be created so further part of logic which then do relation in db is not being executed
FFaizan9/6/2023
i was using exactly same approach as yours, but it didn't sound right. and then there is this message from a contributor. the solution where you create trpc server function just to call an external api sounds really hacky and not natural.
No description
ALAdrian Lysakowski9/6/2023
so the logic is on UI -> fill in user information -> call trpc users route create method on Server -> method inside first try to create users in clerk using fetch -> await response, check if all good -> save created user in my db using with additional property clerkUserId from the response of fetch @mfaizan1 it depends, if u call public extarnal API then it's fine, u can use react query, but if that's the request where u need to pass some "tokens" which are private ones, u can't use react query, as then me using ur app can steal it
FFaizan9/6/2023
ahh got it. thanks for discussion.
ALAdrian Lysakowski9/6/2023
cuz i will see it simply in network tab in request, of the headers that will include ur private tokens
ALAdrian Lysakowski9/6/2023
No description
FFaizan9/6/2023
got it. that's a really good point.
ALAdrian Lysakowski9/6/2023
you could do a fetch, inside "server" component, instead of trpc, but then if ur logic later on in trpc actually depends on response, then it doesn't make sense to have call in component await and then pass it to trpc route πŸ˜„ as in my case once i got response i need to save those users in my db as well πŸ˜„ so it very valid to have it all together inside the method of trpc route

Looking for more? Join the community!

T
tRPC

External calls

Join Server
Recommended Posts
Need help identifying the generic client side type of proceduresHi! I think my question is better explained by what I'm trying to achive than anything else: I likIs there a way to use versioning for procedures?I want to make multiple versions (v1 / v2) for a procedure, can i do it in procedure level?createSSGHelpersI'm trying to fetch data in getStaticProps and getting the issue "Promise<{ paths: { params: { id: nTRPC undefined when exportingHi i am working on merging routers from different files but when exporting the router property it coTRPC retries with new app dir```ts let { data: name, isLoading, isFetching, isError, error } = trpc.home.home.useQuery(); ```opts.input is of type undifined```ts register: publicProcedure.input( RegisterSchema ).mutation(async (opts) => { Server-side error tracing with DatadogHey, has anyone had any luck setting up tracing with tRPC? Specifically with `dd-trace-js`. We’re uConfiguration helpHello! I want to apply the following configuration on the client: https://tanstack.com/query/v4/docI'm curious to know if anyone has any suggestions on how I can track the replies to the emailsI'm curious to know if anyone has any suggestions on how I can track the replies to the emails I sentRPC subscription : Access to socket ID from subscriptionI'm trying to implement user online status in a reliable way on my app, on the "live" part of my appHaving Issue With Context in App Directory Next.jsI am having an issue with creatin the trpc context with both the session and prisma. I am trying to tRPC querying data via function not workingIn the below code, `fetchSocialMediaData` is logging `themeId` but, not `response`, getting error asNext.js app router + TRPC...how to set it up?> **Note** > You can already use tRPC with app directory, by: > > - using `@trpc/client` directly inHow do I setup App router + TRPC + Lucia Auth? (protected routes)I'm trying to setup tRPC with Lucia in app router but I struggle to make protected routes work. I mNEXT.JS / Serverless AWSConfigured trpc locally. Everything works great. When deploying via serverless on aws - mutations doHow do I set a context dynamically?I don't fully understand middleware in trpc and especially using it for adminProcedures. So my trpcHow to make LoaderAndError component which is type safe?I i have a query like this `const { data, isLoading, isError } = trpc.settings.get.useQuery();` NowTRPC vanilla client load failed when called on mobile browserHi, I have created a vanilla client to use TRPC without hooks in a NextJS project: ``` import { cre`createCaller` and RSC - with next-authI've been upgrading my trpc routers and handlers to support edge+app router with drizzle and next-auuseQuery always fetching when active on pageHi, I was call my procedure like this, using NextJs (page directory) const { isLoading, isError, isS