Skip to content

Commit

Permalink
Merge pull request #203 from jonian/global-middleware-prepend
Browse files Browse the repository at this point in the history
feat: add option to prepend the global middleware
  • Loading branch information
manchenkoff authored Oct 28, 2024
2 parents 65b3d30 + 94c3346 commit c8b6d86
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineNuxtConfig({
globalMiddleware: {
allow404WithoutAuth: true,
enabled: false,
prepend: false,
},
},
})
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const defaultModuleOptions: ModuleOptions = {
},
globalMiddleware: {
enabled: false,
prepend: false,
allow404WithoutAuth: true,
},
logLevel: 3,
Expand Down
2 changes: 2 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default defineNuxtModule<ModuleOptions>({
name: 'sanctum:auth:global',
path: resolver.resolve('./runtime/middleware/sanctum.global'),
global: true,
}, {
prepend: sanctumConfig.globalMiddleware.prepend,
})

logger.info('Sanctum module initialized with global middleware')
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export interface GlobalMiddlewareOptions {
* @default false
*/
enabled: boolean
/**
* Determines whether the global middleware is prepended.
* @default false
*/
prepend: boolean
/**
* Determines whether to allow 404 pages without authentication.
* @default true
Expand Down

0 comments on commit c8b6d86

Please sign in to comment.