activist
activist copied to clipboard
Experiment with and apply global middleware file rather than file based
Terms
- [X] I have searched open and closed feature requests
- [X] I agree to follow activist's Code of Conduct
Description
This issue would investigate and implement a file that would serve as the global middleware for the full platform. So rather than having a file based system where we put the middleware in the route that needs it, we'd instead have one file that then defines all the routes that get a specific requirement in order to access them.
Contribution
@UnknownSean8 said he had interest in this one :) Can you write in here and I'll assign? Very happy to support!
Two approaches I've found (using Nuxt's middleware guide) are using global middleware (so run the middleware on every page, check if the page matches some criteria, and do something based on that) and setting middleware at build time (use the pages:extend lifecycle hook as part of the nuxt.config.ts file to go through the pages and add middleware based on criteria). The former has the advantage of potentially being more readable since it places all the middleware related files in the middleware directory and seems to be more what you were going for based on the description. The latter has the advantage of not running every time on every page and is more similar to the current system except that all of the middleware additions can be in one file.
I'd say that performance should trump readability for this, @Robot8lover, so let's go for the second option :) Can we have one separate file that's loaded into the nuxt.config.ts so it's at least separated out from that larger file?
Happy to assign if you'd like to work on this!
Sure, I'd love to work on this.
And yes, we can just import into the nuxt.config.ts so all that can be separated.
Thanks for the confirmation and picking this up, @Robot8lover!
Right now, the only pages that use middleware are the create pages, which check if the user is signed in. Are there any other pages that should get middleware at this point?
For right now those are fine, and then we can expand it with individual issues moving forward :)
My apologies for getting back to this so late, but I think this PR should accomplish it.
No stress at all, @Robot8lover! Great to hear from you :) We'll check it this weekend as we get to things 😊
Closed by #1017 🚀 Appreciate the support as always, @Robot8lover! Please let us know if there's something else of interest or you'd like a suggestion. Happy to also hop on a call to discuss potential ideas for future steps or ideas you might have :)