基本認證
用於基本認證的 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 | boolean | true | 啟用或停用基本認證。 |
使用者 | 陣列 | [] | 使用者陣列。每個使用者必須包含 username 和 password 屬性。也可以格式化為字串 <username>:<password>,<username2>:<password2> |
使用者分隔符 | string | , | 使用者字串的分隔符。 |
允許路由 | string[] | [] | 不受基本認證保護的路由陣列。支援正則表示式模式。 |
所有選項也可以透過環境變數設定,使用 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