henrydiaosi/ai-framework/auth
Claude Code and agent skill by henrydiaosi/ai-framework
- community
Checking that the SKILL.md file is still in the repository.
Install
npx vskill@latest install henrydiaosi/ai-framework/authSKILL.md
Auth 认证模块
层级:第 3 层(子模块文档)上层:src/SKILL.md
<!-- @index
| key | tags | desc | |
|---|---|---|---|
| api:login | 登录,Token,认证 | 用户登录接口 | |
| api:register | 注册,用户,创建 | 用户注册接口 | |
| api:refreshToken | Token,刷新,续期 | Token刷新接口 | |
| api:logout | 登出,退出,Session | 用户登出接口 |
-->
<!-- NAV_START
文档导航 (总 270 行)
| 章节 | 行号 | 说明 | |
|---|---|---|---|
| 模块概述 | 20-55 | 职责、架构、设计模式 | |
| API:login | 60-97 | 登录接口 | |
| API:register | 99-138 | 注册接口 | |
| API:refreshToken | 140-163 | Token刷新接口 | |
| API:logout | 165-185 | 登出接口 | |
| 开发规范 | 187-228 | 错误处理、日志、验证 | |
| 测试要求 | 230-240 | 测试覆盖率要求 | |
| 依赖关系 | 242-255 | 内外部依赖 | |
| 常见问题 | 260-270 | FAQ |
NAV_END -->
模块概述
- 职责:处理用户认证相关的所有功能
- 位置:src/modules/auth/
- 依赖:core/database, core/logger, core/error
模块架构
设计模式
- Service 模式:业务逻辑封装在 AuthService 中
- DTO 模式:使用 Data Transfer Object 进行数据验证
关键概念
- JWT Token:使用 JSON Web Token 进行身份验证
- Refresh Token:支持 Token 刷新机制
- Password Hash:使用 bcrypt 进行密码加密
API 文档
AuthService
<!-- API:login START -->
login(dto: LoginDto): Promise<TokenPair>
功能说明:用户登录,验证凭据并返回 Token
参数:
dto(LoginDto): 登录数据传输对象email(string): 用户邮箱password(string): 用户密码
返回值:
- (Promise<TokenPair>): Token 对象
accessToken(string): 访问令牌refreshToken(string): 刷新令牌
抛出异常:
ValidationError: 当参数验证失败时UnauthorizedError: 当凭据无效时
使用示例:
注意事项:
- 密码错误超过 5 次会锁定账户 15 分钟
- accessToken 有效期为 15 分钟
- refreshToken 有效期为 7 天
<!-- API:login END -->
<!-- API:register START -->
register(dto: RegisterDto): Promise<User>
功能说明:用户注册,创建新用户账户
参数:
dto(RegisterDto): 注册数据传输对象email(string): 用户邮箱password(string): 用户密码(至少 8 位)name(string): 用户名称
返回值:
- (Promise<User>): 创建的用户对象
抛出异常:
ValidationError: 当参数验证失败时ConflictError: 当邮箱已被注册时
使用示例:
注意事项:
- 邮箱必须唯一
- 密码会自动进行 bcrypt 加密
- 注册成功后会发送验证邮件
<!-- API:register END -->
<!-- API:refreshToken START -->
refreshToken(token: string): Promise<TokenPair>
功能说明:使用 Refresh Token 获取新的 Token 对
参数:
token(string): 有效的 Refresh Token
返回值:
- (Promise<TokenPair>): 新的 Token 对
抛出异常:
UnauthorizedError: 当 Token 无效或已过期时
使用示例:
<!-- API:refreshToken END -->
<!-- API:logout START -->
logout(userId: string): Promise<void>
功能说明:用户登出,使当前 Token 失效
参数:
userId(string): 用户 ID
返回值:
- (Promise<void>)
使用示例:
<!-- API:logout END -->
模块开发规范
错误处理
日志记录
数据验证
测试要求
- 单元测试覆盖率:> 80%
- 测试文件位置:
__tests__/ - 必须测试的场景:
- 正常登录流程
- 密码错误处理
- Token 刷新
- 账户锁定机制
依赖关系
外部依赖
jsonwebtoken: JWT 生成和验证bcrypt: 密码加密zod: 数据验证
内部依赖
@/core/database: 数据库操作@/core/logger: 日志记录@/core/error: 错误处理@/modules/user: 用户信息查询
相关文档
常见问题
- Token 过期后如何处理?
使用 refreshToken 方法获取新的 Token 对。
- 如何实现"记住我"功能?
延长 refreshToken 的有效期至 30 天。
- 密码重置流程是什么?
调用 forgotPassword 发送重置邮件,用户点击链接后调用 resetPassword。
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingexample-project/src/modules/auth/SKILL.md
Popularity
- Repository stars
- 54
- Repository forks
- 11
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/henrydiaosi/ai-framework/auth)