Middleware
Is it possible to add middleware based on the directories I have?
for example, I have directory
A and B and I want to run a permission check on each directory for all queries/mutations inside of it, what's the best way to do this? I considered wrapping the query/mutation and using a custom version of it. but would be much better if we could define a middleware.5 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I don't think there is file / directory level middleware in convex, you'll need to define custom queries/mutations/actions
There is a guide in the documentation to do it in a clean way using convex-helpers library
Customizing serverless functions without middleware
Re-use code and centralize request handler definitions with discoverability and type safety and without the indirection of middleware or nesting of wr...
Yeah I already seen that, I just wanted a directory level middleware
One pattern you might like is to have somefolder/functions.ts and put the middleware for that folder there and have the policy/lint be that you import query/mutation/action from
./functions wherever you are