Open
Description
Environment
@sidebase/nuxt-auth 0.9.4 and 0.10.0
Nuxt 3.14.1592
Reproduction
no need reproduction
Describe the bug
I am experiencing a significant issue with the sidebase/nuxt-auth module in my Nuxt 3 project. After installing the module, all my custom middleware stopped working, and I started encountering TypeScript errors when defining middleware in definePageMeta.
Here’s a detailed breakdown of the problem:
- When I define custom middleware (e.g., "authme") in definePageMeta:
definePageMeta({
middleware: "authme",
});
I get the following TypeScript error:
Type '"authme"' is not assignable to type '"sidebase-auth" | NavigationGuard | ("sidebase-auth" | NavigationGuard)[] | undefined'.
- Upon investigating, I found that the generated type definitions in
.nuxt/types/middleware.d.ts
look like this:
import type { NavigationGuard } from 'vue-router'
export type MiddlewareKey = "sidebase-auth"
declare module "../../node_modules/nuxt/dist/pages/runtime/composables" {
interface PageMeta {
middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>
}
}
declare module 'nitropack' {
interface NitroRouteConfig {
appMiddleware?: MiddlewareKey | MiddlewareKey[] | Record<MiddlewareKey, boolean>
}
}
Additional context
Final Issue Summary:
The root cause of this issue is that the internal middleware system of sidebase/nuxt-auth
overrides the default Nuxt middleware behavior. As a result:
- It restricts the use of custom middleware in the
middleware
property ofPageMeta
. - It enforces only the use of sidebase-auth, making it impossible to use custom middleware alongside it.
- This severely limits flexibility and causes unexpected runtime behavior, such as global middleware not triggering during route transitions.
Logs
No response