From 94c334652434ceaaaa82b791c603abf6d499d6cd Mon Sep 17 00:00:00 2001 From: Jonian Guveli Date: Sun, 27 Oct 2024 10:33:16 +0200 Subject: [PATCH] feat: add option to prepend the global middleware --- playground/nuxt.config.ts | 1 + src/config.ts | 1 + src/module.ts | 2 ++ src/runtime/types/options.ts | 5 +++++ 4 files changed, 9 insertions(+) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 53d8f11..172c72b 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -23,6 +23,7 @@ export default defineNuxtConfig({ globalMiddleware: { allow404WithoutAuth: true, enabled: false, + prepend: false, }, }, }) diff --git a/src/config.ts b/src/config.ts index cb8b459..a869bb4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -29,6 +29,7 @@ export const defaultModuleOptions: ModuleOptions = { }, globalMiddleware: { enabled: false, + prepend: false, allow404WithoutAuth: true, }, logLevel: 3, diff --git a/src/module.ts b/src/module.ts index 9cd48a3..444a94b 100644 --- a/src/module.ts +++ b/src/module.ts @@ -48,6 +48,8 @@ export default defineNuxtModule({ 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') diff --git a/src/runtime/types/options.ts b/src/runtime/types/options.ts index e961f3d..d5907a6 100644 --- a/src/runtime/types/options.ts +++ b/src/runtime/types/options.ts @@ -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