Acme

快速参考

私有 Registry 认证配置快速参考卡片

服务端快速配置

生成令牌

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

配置环境变量

.env.local
REGISTRY_TOKEN=your_generated_token

启动服务

pnpm dev

客户端快速配置

配置 components.json

components.json
{
  "registries": {
    "@acme": {
      "url": "https://your-domain.com/api/registry/{name}",
      "headers": {
        "Authorization": "Bearer ${REGISTRY_TOKEN}"
      }
    }
  }
}

设置环境变量

.env.local
REGISTRY_TOKEN=your_token

安装组件

npx shadcn@latest add @acme/button

认证方式速查

方式请求头/参数示例推荐度
Bearer TokenAuthorizationBearer YOUR_TOKEN⭐⭐⭐⭐⭐
API KeyX-API-KeyYOUR_TOKEN⭐⭐⭐⭐
查询参数token?token=YOUR_TOKEN⭐⭐ (仅测试)

测试命令速查

成功请求(200)

curl -H "Authorization: Bearer YOUR_TOKEN" \
  http://localhost:3000/api/registry/hello-world

无认证(401)

curl http://localhost:3000/api/registry/hello-world

错误令牌(401)

curl -H "Authorization: Bearer wrong_token" \
  http://localhost:3000/api/registry/hello-world

HTTP 状态码

状态码含义原因
200成功认证通过,组件返回
401未授权令牌缺失或无效
403禁止访问无权限访问该组件
404未找到组件不存在
500服务器错误服务器内部错误

环境变量

变量名必需说明
REGISTRY_TOKENRegistry 认证令牌
JWT_SECRETJWT 密钥(高级)
DATABASE_URL数据库连接(高级)

常用文件路径

project/
├── .env.local                                    # 环境变量
├── env.example                                   # 环境变量示例
├── registry.json                                 # Registry 配置
├── app/api/registry/[name]/route.ts             # API 路由
├── content/docs/registry/authentication.mdx      # 认证文档
└── scripts/test-auth.sh                         # 测试脚本

故障排查速查

问题:401 Unauthorized

解决方案:

  1. 检查环境变量:echo $REGISTRY_TOKEN
  2. 确认令牌格式正确
  3. 重启开发服务器
  4. 检查 .env.local 文件

问题:403 Forbidden

解决方案:

  1. 令牌有效但无权限
  2. 检查 RBAC 配置
  3. 联系管理员

问题:404 Not Found

解决方案:

  1. 确认组件名称正确
  2. 运行 pnpm registry:build
  3. 检查 public/r/ 目录

相关文档