tRPC, Is it just for front end?

I just spent a few hours trying to use tRPC endpoint inside a NextAuth callback function, only to finally give up and use prisma directly. Now that I reflect on it, tRPC IS part of the server right? Did I just try to call an endpoint from my own server? 🤦‍♂️🤦‍♂️🤦‍♂️ I hope I’m wrong. be gentle 🤣
6 Replies
royanger
royanger2y ago
You hit it on the head. tRPC is about a server endpoint, so the client can perform queries and mutations. If you are on the server side (the NextAuth callback or another serverless function, getServerSideProps, etc) then you don't want to use tRPC. That said, if you need the same logic you could write a function, then use that same function inside your tRPC function and on your server side code.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cje
cje2y ago
extracting functions is the short answer i go through it in more detail here https://www.youtube.com/watch?v=G2ZzmgShHgQ&t=539s
shaaah
shaaah2y ago
So tRPC isnt really helpful if the front end is separately created?
Mendy
Mendy2y ago
Thanks everyone 🙏 I appreciate the detailed responses! I believe so.
royanger
royanger2y ago
I’m not sure what you mean by ‘separately created’ but tRPC is good with a monorepo that contains both your friontend backend.
Want results from more Discord servers?
Add your server