nuxt-basic-auth

Nuxt Module for Basic Authentication

Basic Auth

npm versionnpm downloadsLicenseNuxt

Nuxt 3 Module for Basic Authentication.

Features

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

Quick Setup

  1. Add @kgierke/nuxt-basic-auth dependency to your project
# Using pnpmpnpm add -D @kgierke/nuxt-basic-auth# Using yarnyarn add --dev @kgierke/nuxt-basic-auth# Using npmnpm install --save-dev @kgierke/nuxt-basic-auth
  1. Add @kgierke/nuxt-basic-auth to the modules section of nuxt.config.ts
export default defineNuxtConfig({  modules: ["@kgierke/nuxt-basic-auth"],});
  1. Configure the module in nuxt.config.ts
export default defineNuxtConfig({  modules: ["@kgierke/nuxt-basic-auth"],  basicAuth: {    enabled: true,    users: [      {        username: "admin",        password: "admin",      },    ],    // Optional: Whitelist routes    // allowedRoutes: ["/api/.*"],  },});

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

Options

OptionTypeDefaultDescription
enabledbooleantrueEnables or disables Basic Auth.
usersarray[]Array of users. Each user must have a username and password property. Can also be formatted as string <username>:<password>,<username2>:<password2>
allowedRoutesstring[][]Array of routes that are not protected by Basic Auth. Supports regex patterns.

Development

# Install dependenciesnpm install# Generate type stubsnpm run dev:prepare# Develop with the playgroundnpm run dev# Build the playgroundnpm run dev:build# Run ESLintnpm run lint# Run Vitestnpm run testnpm run test:watch# Release new versionnpm run release