Skip to content

Conversation

felix-dolderer
Copy link
Contributor

@felix-dolderer felix-dolderer commented Aug 16, 2024

πŸ”— Linked issue

Closes #114

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to 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

  1. I'm not sure if auto-importing the existing middleware functions (hankoLoggedIn, hankoLoggedOut) is necessary or the best way to make them accessible for building custom middleware on top of them.
  2. How can I write tests for the logged-in behaviour? I logged in with my demo Hanko-API, took my current cookie and used that to make sure my tests were passing. This approach is obviously hard to replicate for other people who want to run the tests. (Addition: And it breaks automated testing.)

Copy link
Collaborator

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I missed this PR! one comment/question

@felix-dolderer felix-dolderer marked this pull request as draft April 25, 2025 15:41
@felix-dolderer felix-dolderer marked this pull request as ready for review June 15, 2025 15:12
Copy link

codecov bot commented Jun 15, 2025

Codecov Report

Attention: Patch coverage is 34.88372% with 28 lines in your changes missing coverage. Please review.

Project coverage is 44.76%. Comparing base (c8d99bf) to head (8eedef4).
Report is 182 commits behind head on main.

Files with missing lines Patch % Lines
src/runtime/middleware/global-logged-in.ts 0.00% 19 Missing and 1 partial ⚠️
src/runtime/middleware/logged-in.ts 0.00% 3 Missing ⚠️
src/runtime/middleware/logged-out.ts 25.00% 3 Missing ⚠️
src/module.ts 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #163      +/-   ##
==========================================
+ Coverage   36.82%   44.76%   +7.94%     
==========================================
  Files          16        9       -7     
  Lines         410      239     -171     
  Branches       25       17       -8     
==========================================
- Hits          151      107      -44     
+ Misses        245      126     -119     
+ Partials       14        6       -8     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@felix-dolderer
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global middleware option

2 participants