rustclan
rustclan2y ago

trpc pipe middleware

Hey all. I'm currently trying to create a middle ware on endpoints using the new pipe API. This is on a specific route which is formatted like: http://localhost:3000/dashboard/811452295324762131/page Is it possible to retrieve the dynamic id which is in this URL, in my middleware? I really need to access this for the middleware to be possible to use. Essentially I need to check if the current user has permission to access this guildId.
const enforceGuildPermissions = enforceUserLoggedIn.unstable_pipe(
async ({ ctx, next }) => {
return next({
ctx: {
session: { ...ctx.session, user: ctx.session.user },
},
});
}
);
const enforceGuildPermissions = enforceUserLoggedIn.unstable_pipe(
async ({ ctx, next }) => {
return next({
ctx: {
session: { ...ctx.session, user: ctx.session.user },
},
});
}
);
There unfortunetly doesn't seem to be any req property in the pipe api which could give me router information.
3 Replies
Nick
Nick2y ago
Middlewares can use context, so you can put this data in context first
Nick
Nick2y ago
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.
rustclan
rustclanOP2y ago
Thank you! I found a way to do this which was using rawInput prop, but shall give this a read too.

Did you find this page helpful?