认证接口
用户注册
注册新用户并返回 JWT 令牌。
POST /api/v1/auth/register
请求体
json
{
"email": "user@example.com",
"username": "johndoe",
"nickname": "John Doe",
"password": "securepass123"
}| 字段 | 类型 | 必填 | 约束 |
|---|---|---|---|
email | string | 是 | 有效邮箱格式 |
username | string | 是 | 3-64 字符 |
nickname | string | 否 | - |
password | string | 是 | 8-128 字符 |
响应
json
{
"code": 0,
"message": "success",
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 7200
},
"trace_id": "req-abc-123"
}错误
| 状态码 | 说明 |
|---|---|
| 400 | 参数校验失败 |
| 409 | 邮箱或用户名已存在 |
用户登录
使用邮箱和密码登录。
POST /api/v1/auth/login
请求体
json
{
"email": "user@example.com",
"password": "securepass123"
}| 字段 | 类型 | 必填 |
|---|---|---|
email | string | 是 |
password | string | 是 |
响应
同注册接口,返回 TokenPair。
错误
| 状态码 | 说明 |
|---|---|
| 400 | 参数校验失败 |
| 401 | 邮箱或密码错误 |
刷新令牌
使用 refresh_token 获取新的令牌对。
POST /api/v1/auth/refresh
请求体
json
{
"refresh_token": "eyJhbGciOiJIUzI1NiIs..."
}响应
同注册接口,返回新的 TokenPair。
错误
| 状态码 | 说明 |
|---|---|
| 400 | 参数校验失败 |
| 401 | Refresh Token 无效或过期 |
修改密码
修改当前用户密码,需要认证。
POST /api/v1/password
请求头
Authorization: Bearer <access_token>
X-Tenant-ID: <tenant_id>请求体
json
{
"old_password": "oldpass123",
"new_password": "newpass456"
}| 字段 | 类型 | 必填 | 约束 |
|---|---|---|---|
old_password | string | 是 | - |
new_password | string | 是 | 8-128 字符 |
响应
json
{
"code": 0,
"message": "success",
"data": null,
"trace_id": "req-abc-123"
}获取当前用户
获取当前认证用户的个人资料。
GET /api/v1/profile
请求头
Authorization: Bearer <access_token>
X-Tenant-ID: <tenant_id>响应
json
{
"code": 0,
"message": "success",
"data": {
"id": 1,
"email": "user@example.com",
"username": "johndoe",
"nickname": "John Doe",
"avatar": "",
"status": 1,
"tenant_id": "tenant-001"
},
"trace_id": "req-abc-123"
}
