登录认证
NestJS 后端采用 JWT + 可选 Redis 双模式认证。
接口说明
获取验证码
http
GET /api/v1/auth/captcha响应:
json
{
"code": "00000",
"msg": "成功",
"data": {
"captchaId": "uuid",
"captchaBase64": "data:image/png;base64,..."
}
}登录
http
POST /api/v1/auth/login
Content-Type: application/jsonjson
{
"username": "admin",
"password": "123456",
"captchaId": "uuid",
"captchaCode": "1234"
}响应:
json
{
"code": "00000",
"msg": "成功",
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "eyJhbGciOiJIUzI1NiIs...",
"tokenType": "Bearer",
"expiresIn": 7200000
}
}刷新令牌
http
POST /api/v1/auth/refresh-token?refreshToken=eyJhbGc...响应:
json
{
"code": "00000",
"msg": "成功",
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "eyJhbGciOiJIUzI1NiIs...",
"tokenType": "Bearer",
"expiresIn": 7200000
}
}退出登录
http
DELETE /api/v1/auth/logout
Authorization: Bearer <token>核心模块位置
text
src/
├── auth/
│ ├── auth.controller.ts
│ ├── auth.service.ts
│ └── dto/
│ ├── login-request.dto.ts
│ └── login-result.dto.ts
├── auth/strategies/jwt.strategy.ts
├── common/guards/jwt-auth.guard.ts
└── common/decorators/auth.decorator.ts下一步:
