Skip to content

globalAppMiddleware should be configurable at runtime, not only at build time #1091

Description

@agracia-foticos

Describe the feature

Problem: The globalAppMiddleware: true option (which protects all routes requiring login) is set conditionally in nuxt.config.ts at build time. Instances that require mandatory login and those that allow guest access cannot share the same build.

Use case: Single build, multiple instances — some require login to browse (isLoginRequiredToAccess=true), others allow guest access. This is currently controlled by a JSON config file read at build time.

Expected behavior: Allow globalAppMiddleware behavior to be driven by a runtimeConfig value (e.g. NUXT_AUTH_GLOBAL_MIDDLEWARE=true), so the middleware reads the flag at request time and decides whether to enforce authentication, rather than the middleware being registered or not at compile time.

Note: We are aware this may require architectural changes since Nuxt middleware registration happens at build time. An alternative acceptable solution would be a "compile-in but runtime-skippable" global middleware that checks a runtimeConfig boolean before enforcing auth.

How would you implement this?

No response

Additional information

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn improvement that needs to be addedpendingAn issue waiting for triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions