trachesT
tRPC8mo ago
11 replies
traches

Can I extend the procedure builder?

Authorization in my app is somewhat complicated; I have various resources, and I often have to validate the current user's relation to that resource before allowing them access.

Currently I'm doing this:
  myProcedure: protectedProcedure
    .input(myQuerySchema)
    .query(authorize(myQuery, authorizationConfig)),

- authorize is a custom function that wraps a mutation in an authorization check, which is defined by the config.
- The types of the query and config are related, because the authorization check uses the procedure's input.

What I really want to do is this:
  myProcedure: protectedProcedure
    .input(myQuerySchema)
    .authorize(authorizationConfig)
    .query(myQuery)


Any advice? I've looked at using .meta(), but middleware doesn't know about the input types does it?
Solution
Yeah it's possible to do what you want:
image.png
Was this page helpful?