Skip to content

sidebase/nuxt-auth Overrides Custom Middleware and Causes TypeScript Errors #980

Open
@alirezatabi

Description

@alirezatabi

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:

  1. 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'.
  1. 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:

  1. It restricts the use of custom middleware in the middleware property of PageMeta.
  2. It enforces only the use of sidebase-auth, making it impossible to use custom middleware alongside it.
  3. This severely limits flexibility and causes unexpected runtime behavior, such as global middleware not triggering during route transitions.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionA question about NuxtAuth

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions