基本认证
用于基本认证的 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