Basic Auth

Optional Enable Basic Auth to protect your application from unwanted traffic.


This middleware will implement Basic Auth in your application. Only users with correct credentials passed to the browser prompt will be able to see the application. Others will be automatically rejected.

ℹ Read more about HTTP Authentication here.

Usage

This middleware is disabled by default. You can enable it globally like following:

nuxt.config.ts
export default defineNuxtConfig({
  security: {
    basicAuth: {
      // options
    }
  }
})

Options

Basic Auth accepts following configuration options:

type BasicAuth = {
  exclude?: string[];
  include?: string[];
  name: string;
  pass: string;
  enabled: boolean;
  message: string;
}

exclude

  • Default: -

Paths to exclude from Basic Auth functionality.

include

  • Default: -

Paths to include in Basic Auth functionality.

name

  • Default: -

User name that is required for user/pass flow

pass

  • Default: -

User password that is required for user/pass flow

enabled

  • Default: -

Boolean value to indicate whether a BasicAuth is enabled or not.

message

  • Default: -

Message that is added to WWW-Authenticate header and to Basic realm=${message} value