feat: globalMiddleware option#163
Conversation
danielroe
left a comment
There was a problem hiding this comment.
sorry I missed this PR! one comment/question
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #163 +/- ##
==========================================
- Coverage 36.82% 29.09% -7.74%
==========================================
Files 16 9 -7
Lines 410 110 -300
Branches 25 30 +5
==========================================
- Hits 151 32 -119
+ Misses 245 57 -188
- Partials 14 21 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
02ad6a5 to
b9471a9
Compare
|
I noticed none of the auth modules for nuxt have tests for the logged in state. I decided to fix that and added tests that mock useHanko and useRequestEvent in a way that the middleware accepts the request as authenticated. |
- Introduced `globalMiddleware` option in the Nuxt configuration to protect all pages by default. - Added new route middleware for handling access based on user authentication status. - Updated README to include details on global middleware usage and configuration. - Created example pages demonstrating the use of `allow` and `deny` settings in pageMeta. - Enhanced test coverage for global middleware scenarios, including client-side and SSR tests.
…tion - Introduced a new `page-meta.d.ts` file to define the `hanko` property in the `PageMeta` interface. - Updated the module to prepare type references for the new page metadata definitions.
…ting - Added a computed property to determine if global middleware is active. - Updated the navigation structure in `app.vue` to conditionally render links based on the global middleware state. - Enhanced the module to include `globalMiddleware` in the Nuxt configuration for improved route protection.
- Replaced the old page-meta.d.ts file with a new page-meta-global.d.ts to avoid automatic inclusion in the TypeScript project. - Updated type preparation in the module to reference the new file for conditional loading based on globalMiddleware settings. - Removed the outdated page-meta.d.ts file.
- Added a computed property to check if the application is running in a test environment. - Updated the navigation structure in `app.vue` to conditionally render links based on the test environment and global middleware state.
|
I synced all forked repositories and didn't pay attention that I have a PR tied to this fork. I really dislike doing code review when people rebase their branches because you lose your review progress - So I'm sorry for doing that myself now. 🙈 Made some small improvements to the PR after the rebase. |
|
Is anything still blocking this PR? Personally I think it is crucial to have a global middleware instead of setting it per page. IMO it would be fine if Hanko would just export its middleware, see: #114 (comment) |
This PR also exposes the existing middleswares so you can build your own pattern around that. I'm not aware of anything blocking this, it just seems to be low priority and I'm not a maintainer so I cannot just merge the PR. |
🔗 Linked issue
Closes #114
❓ Type of change
📚 Description
Adds a configuration option that adds a global middleware. This option requires being logged in for all pages (unless otherwise specified on the individual page)
Exposes and auto-imports the middleware functions (
hankoLoggedIn,hankoLoggedOut) so they can be imported in a simple and typesafe way.ℹ️ Help / Review wanted
hankoLoggedIn,hankoLoggedOut) is necessary or the best way to make them accessible for building custom middleware on top of them.