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

feat: add option to prepend the global middleware #203

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

jonian
Copy link
Contributor

@jonian jonian commented Oct 13, 2024

Middlewares from modules have lower order from the ones in the middleware folder. This is a problem if we want to run an auth related global middleware.

For example, we want to run sanctum:auth:global to check if the user is authenticated before running a global middleware to check if the user has the right permissions.

This adds support for prepending the sanctum:auth:global middleware to the list of existing middleware, more info here.

globalMiddleware: {
  // Default value is false
  prepend: true,
},

@manchenkoff
Copy link
Owner

Hey @jonian, thanks a lot for the contribution! Could you also update the options interface in src/runtime/types/options.ts? Also, make sure you run pnpm validate before pushing your changes to check that code is valid.

@manchenkoff manchenkoff assigned manchenkoff and jonian and unassigned manchenkoff Oct 19, 2024
@manchenkoff manchenkoff self-requested a review October 19, 2024 22:16
src/module.ts Show resolved Hide resolved
@jonian jonian force-pushed the global-middleware-prepend branch from 6133b14 to d30fb04 Compare October 27, 2024 08:30
@jonian jonian force-pushed the global-middleware-prepend branch from d30fb04 to 94c3346 Compare October 27, 2024 08:36
@jonian
Copy link
Contributor Author

jonian commented Oct 27, 2024

@manchenkoff hello! Thank you for looking at this. I updated the options interface and used pnpm validate to make sure that code is valid.

src/module.ts Show resolved Hide resolved
@manchenkoff
Copy link
Owner

It will be merged and released as 0.5.1 later today

@manchenkoff manchenkoff merged commit c8b6d86 into manchenkoff:main Oct 28, 2024
2 checks passed
@jonian jonian deleted the global-middleware-prepend branch October 28, 2024 07:49
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.

2 participants