Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with and apply global middleware file rather than file based #903

Open
2 tasks done
andrewtavis opened this issue Jun 15, 2024 · 8 comments
Open
2 tasks done
Assignees
Labels
feature New feature or request hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed

Comments

@andrewtavis
Copy link
Member

andrewtavis commented Jun 15, 2024

Terms

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!

@andrewtavis andrewtavis added feature New feature or request help wanted Extra attention is needed labels Jun 15, 2024
@andrewtavis andrewtavis added the hacktoberfest Included as a part of Hacktoberfest label Oct 1, 2024
@Robot8lover
Copy link
Contributor

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.

@andrewtavis
Copy link
Member Author

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?

@andrewtavis
Copy link
Member Author

Happy to assign if you'd like to work on this!

@Robot8lover
Copy link
Contributor

Sure, I'd love to work on this.

@Robot8lover
Copy link
Contributor

And yes, we can just import into the nuxt.config.ts so all that can be separated.

@andrewtavis
Copy link
Member Author

Thanks for the confirmation and picking this up, @Robot8lover!

@Robot8lover
Copy link
Contributor

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?

@andrewtavis
Copy link
Member Author

For right now those are fine, and then we can expand it with individual issues moving forward :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed
Projects
Status: Todo
Development

No branches or pull requests

2 participants