how can i get procedure name?
is it possible to get procedure name? i would like to append a service to ctx based on procedure name? is this possible in trpc?
6 Replies
Sounds like you want to create a new base procedure which is used in certain situations. Middlewares can add/modify to the context type IIRC. (Could be misremembering that last bit though)
Define Procedures | tRPC
- A publicProcedure can be viewed as the equivalent of a REST-endpoint or a function.
Ah yes I’m remembering right https://trpc.io/docs/context#example-for-inner--outer-context
Context | tRPC
Your context holds data that all of your tRPC procedures will have access to, and is a great place to put things like database connections or authentication information.
im looking for a way to inject a service in each procedure without having to add the same middleware to procedure
for example, i have a auth serivce, whihc does both signup, signin, getSession and signout. i'd like to inject the service into the aut procedure
in another procedure, i have a service which does multiple things grouped by a procedure.
how can i achieve this without having to add middleware to each procedure
im using next js middleware which makes sure a user is logged in. this means i'll have 1 procedure for my entire application. i want each route in this procedure to implement or share a service
You add the middleware to a base procedure once and export it to re-use everywhere. If you need the behaviour of the middleware to change based on the procedure (for instance for authorisation user/admin/super) then you can use "Meta" on your routes to declare the access level needed and the middleware can read that Meta data
sounds perfect. i tried this btw. what if i have a auth route object which exprts auth.signup and auth.sign etcc and i want to inject the service at object level and not at property level? is something like that possible?
whit meta i need to declare it at every route. i want the service to be used in all routes inside the route object
my app router looks like this.
auth and organisation are objects which export auth.signup and organisation.create etcc
auth.signup and auth.sigin or any other property of auth shoulde use the same exact service
im doing this for code organisation and also follow the principle of dry
this is my auth route object
right now im injecting the service using a middleware. but this means i'd have to reate a new procedure for each route group