haardik | LearnWeb3
Including multi-tenant config into tRPC context
Hey all,
I've been working on upgrading my app to support multi-tenancy, inspired by Vercel's Platforms starter kit.
The core of the relevant logic comes down to this Next.js middleware:
This middleware is set up to explicitly exclude requests to
/api
Now, within my tRPC router, it is helpful in certain places to be able to access the tenantSlug
value. I could go and change all my tRPC queries/mutations to take that as input and change client-side code everywhere but that would be hundreds of functions and even more calls in the client code.
I have been thinking about how to get this be part of tRPC's context, but I'm a bit stuck
Currently my context looks like this (i have a mix of HTTP and WebSockets)
Since the middleware ignores requests to /api
- the req
object in context (in case of HTTP calls) doesn't include the subdomain/slug in the rquest headers. I figured someone here had to have run into this in the past and may have figured out a solutin already - so any help is appreciated!6 replies
tRPC Client within Next.js but with external standalone server?
Hi,
I have an old Next.js project that used tRPC and we're currently in the process of separating out the frontend and backend parts of it for various reasons. To reuse code, I was hoping to set up a standalone tRPC Server
In that case, what's the recommended method of setting up a tRPC Client on the Next side? using
@trpc/next
or @trpc/react
?
I tried (briefly) using @trpc/next
and it was giving me issues around not having a QueryClient
set - but im not sure if the react method is the way to go either.3 replies
tRPC Websockets with a standalone Bun Server?
Hey folks!
Experiementing with setting up a standalone tRPC Server using Bun. The HTTP part is great - i'm wondering if anyone has succeeded getting it to work with Bun's websocket server? if not, i'll continue figuring it out and hopefully add an adapter to tRPC.
4 replies
Unable to get mutation to trigger subscription because EventEmitter not being shared
Hey folks,
Been struggling with this for a few hours now hopelessly and trying random things - read all related posts in this forum, on github issues, and stackoverflow - and still don't understand what is going on.
I have a next app with a custom HTTP server and using tRPC. WSLink etc is all fine - i'm doing everything the proper way.
I have a router with these two functions:
I've added a bunch of console logs to help explain.
So, in my logs I see that when the app loads up I get a WS Connection to the server.
On the client side, I have
trpc.chat.onNewMessage.useSubscription
which console logs {names: []}
first and then {names: ['onNewMessage']}
as it should based on the code for the router.
But, when I send a message, the mutation fails to trigger the subscription because it logs {namesSendMsg: []}
i.e. for some reason it does;n't recognize the attached listener
I thought it was because maybe somehow multiple EventEmitter
instances are being created due to HMR - so I did a workaround similar to what we do with Prisma for next dev mode:
src/eventEmitter.ts
:
this did not help either. using this wsee
everywhere doesn't change anything. im lost and have no idea WHY there are supposedly two different event emitter instances being used here?6 replies
How to infer type of a nested object from app router output?
I have a tRPC router than returns a nested object through a db query. It looks like this:
I'd like to infer the type of the
comments
property to use as an interface for props on a component. I tried doing this but this doesn't work:
I was wondering if this is even possible?8 replies