Skip to content

认证接口

用户认证相关的 API 接口。

发送验证码

发送邮箱或短信验证码。

请求

http
POST /api/verify-code/send
Content-Type: application/json

请求体

json
{
  "type": "email",
  "target": "user@example.com"
}
字段类型必填说明
typestringemailsms
targetstring邮箱地址或手机号

响应

成功 (200):

json
{
  "code": 0,
  "message": "验证码发送成功"
}

失败 (400):

json
{
  "code": 1,
  "message": "请求过于频繁,请60秒后重试"
}

验证码登录

使用验证码登录或注册。

请求

http
POST /api/verify-code/verify
Content-Type: application/json

请求体

json
{
  "target": "user@example.com",
  "verifyCode": "123456"
}

响应

成功 (200):

json
{
  "code": 0,
  "message": "验证码校验成功",
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "userId": 123,
  "phone": null,
  "email": "user@example.com"
}

密码登录

使用密码登录。

请求

http
POST /api/auth/login
Content-Type: application/json

请求体

json
{
  "phone": "13800138000",
  "password": "password123"
}

响应

成功 (200):

json
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "userId": 123,
  "phone": "13800138000",
  "email": null
}

用户注册

注册新用户。

请求

http
POST /api/auth/register
Content-Type: application/json

请求体

json
{
  "email": "user@example.com",
  "verifyCode": "123456",
  "password": "password123"
}

响应

成功 (200):

json
{
  "userId": 123,
  "phone": null,
  "email": "user@example.com",
  "createdAt": "2026-01-29T10:30:00Z"
}

登出

登出当前用户(无状态,仅返回成功)。

请求

http
POST /api/auth/logout
Authorization: Bearer <token>

响应

成功 (200):

json
{
  "code": 0,
  "message": "登出成功"
}

Mooting 开发者文档