基本身份驗證
用於基本身份驗證的 Nuxt 3 模組。
功能
- ✅ 易於使用
- ✅ 支援多個使用者
- ✅ 白名單路由
快速設定
使用一個命令將模組安裝到您的 Nuxt 應用程式
npx nuxi module add @kgierke/nuxt-basic-auth
在 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/.*"],
},
});
就這樣!您現在可以在您的 Nuxt 應用程式中使用基本身份驗證了 ✨
選項
選項 | 類型 | 預設值 | 描述 |
---|---|---|---|
enabled | 布林值 | true | 啟用或停用基本身份驗證。 |
users | 陣列 | [] | 使用者陣列。每個使用者必須具有 username 和 password 屬性。也可以格式化為字串 <username>:<password>,<username2>:<password2> |
usersDelimiter | 字串 | , | 使用者字串的分隔符號。 |
allowedRoutes | 字串陣列 | [] | 不受基本身份驗證保護的路由陣列。支援正則表達式模式。 |
所有選項也可以透過環境變數設定,使用 NUXT_BASIC_AUTH_
前綴。例如,NUXT_BASIC_AUTH_ENABLED=true
。
開發
# 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