bret_pat
bret_pat12mo ago

Get query parameters in middleware

Hi! I'm looking to perform authorization inside of middleware and I'm wondering how I can access the parameters that the user queried inside of the middleware? For example, let's say a user requested to look at Workout routine ID 532 in an API call. How would I be able to access the workout ID inside of middleware? I have their userID within CTX but no way to get the url path Thanks!
2 Replies
bret_pat
bret_pat12mo ago
It seems like middleware passes in input and rawInput as paramters but I don't think they're documented as what they do Any idea why "input" is undefined as a middleware parameter but "rawInput" is not?
tristanzajonc
tristanzajonc10mo ago
It doesn't have a type yet. You need to parse it. See this example: https://trpc.io/docs/v9/middlewares#raw-input
Middlewares | tRPC
You are able to add middleware(s) to a whole router with the middleware() method. The middleware(s) will wrap the invocation of the procedure and must pass through its return value.