Skip to content

认证接口 /api/auth ​

控制台账号体系。除注册与登录外都需要带登录令牌:

text
Authorization: Bearer <登录返回的 token>

POST /api/auth/register ​

参数类型必填说明
emailstring是邮箱,会转小写后存储
passwordstring是8–72 位,必须同时包含字母和数字
displayNamestring否昵称,最长 60 字
bash
curl -X POST "https://ai.modelfold.online/api/auth/register" \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","password":"Abcd1234","displayName":"You"}'
json
{
  "ok": true,
  "token": "eyJhbGciOi...",
  "user": {
    "id": "1",
    "email": "you@example.com",
    "displayName": "You",
    "avatarUrl": "",
    "credits": 1000,
    "emailVerified": false,
    "createdAt": "2026-10-16T12:00:00.000Z"
  }
}

注册成功即返回可用的登录令牌(有效期 7 天),并自动发送一封验证邮件。

HTTPerror触发条件
400invalid_email邮箱格式不正确
400password_too_short / password_needs_letter_and_digit密码不满足强度要求
409email_taken邮箱已注册

POST /api/auth/login ​

参数类型必填
emailstring是
passwordstring是
bash
curl -X POST "https://ai.modelfold.online/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","password":"Abcd1234"}'

返回结构与注册一致。

设计说明:无论邮箱是否存在、密码是否正确,失败时都返回完全相同的 401 invalid_credentials(并且账号不存在时也会执行一次哈希计算来拉平响应时间),因此该接口不能用于探测某个邮箱是否已注册。

HTTPerror触发条件
401invalid_credentials邮箱或密码不正确
403account_suspended账号被停用
429—每 IP 每 10 分钟超过 30 次

GET /api/auth/me ​

返回当前登录用户,用于前端启动时校验登录态。

bash
curl "https://ai.modelfold.online/api/auth/me" -H "Authorization: Bearer $TOKEN"

POST /api/auth/logout ​

吊销当前这个会话。其它设备不受影响。

json
{ "ok": true }

相关 ​

ModelFold — 一个 API,接入所有主流 AI 模型。