@kgierke/nuxt-basic-auth

Nuxt 3 Module for Basic Authentication
371,682
Install
npm install @kgierke/nuxt-basic-auth
Latest Version:1.7.0
Vue:3
License:MIT
Last Updated:Oct 22, 2024
Links: npm
Maintainer: kgierke

Basic Auth

npm version npm downloads License Nuxt

Nuxt 3 Module for Basic Authentication.

Features

  • ✅ Simple to use
  • ✅ Supports multiple users
  • ✅ Whitelist routes

Quick Setup

Install the module to your Nuxt application with one command:

npx nuxi module add @kgierke/nuxt-basic-auth

Configure the module in nuxt.config.ts

export default defineNuxtConfig({
  modules: ["@kgierke/nuxt-basic-auth"],

  basicAuth: {
    enabled: true,
    users: [
      {
        username: "admin",
        password: "admin",
      },
    ],
    // Optional: Delimiter for users string
    // usersDelimiter: ",",
    // Optional: Whitelist routes
    // allowedRoutes: ["/api/.*"],
  },
});

That's it! You can now use Basic Auth in your Nuxt app ✨

Options

Option Type Default Description
enabled boolean true Enables or disables Basic Auth.
users array [] Array of users. Each user must have a username and password property. Can also be formatted as string <username>:<password>,<username2>:<password2>
usersDelimiter string , Delimiter for users string.
allowedRoutes string[] [] Array of routes that are not protected by Basic Auth. Supports regex patterns.

All options can also be set through environment variables, using the NUXT_BASIC_AUTH_ prefix. For example, NUXT_BASIC_AUTH_ENABLED=true.

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release

Related Packages

@kgierke/nuxt-matomo

Nuxt Module for Matomo Analytics

2,879

Version History

Version Released License
1.7.0 MIT
1.6.0 MIT
1.5.0 MIT
1.4.0 MIT
1.3.1 MIT