tRPCttRPC
Powered by
trachesT
tRPC•9mo 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)),
  myProcedure: protectedProcedure
    .input(myQuerySchema)
    .query(authorize(myQuery, authorizationConfig)),

-
authorize
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)
  myProcedure: protectedProcedure
    .input(myQuerySchema)
    .authorize(authorizationConfig)
    .query(myQuery)


Any advice? I've looked at using
.meta()
.meta()
, but middleware doesn't know about the input types does it?
Solution
Yeah it's possible to do what you want:
image.png
Jump to solution
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Can I alter the context in a procedure?
LiamLLiam / ❓-help
3y ago
how can i get procedure name?
CaptainCCaptain / ❓-help
4y ago
How can I infer the trpc.procedure.mutationOptions type?
AnonTGAAnonTG / ❓-help
2mo ago
How can I cache a single procedure?
Mark LMMark L / ❓-help
4y ago