认证接口 /api/auth
控制台账号体系。除注册与登录外都需要带登录令牌:
text
Authorization: Bearer <登录返回的 token>POST /api/auth/register
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
email | string | 是 | 邮箱,会转小写后存储 |
password | string | 是 | 8–72 位,必须同时包含字母和数字 |
displayName | string | 否 | 昵称,最长 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 天),并自动发送一封验证邮件。
| HTTP | error | 触发条件 |
|---|---|---|
400 | invalid_email | 邮箱格式不正确 |
400 | password_too_short / password_needs_letter_and_digit | 密码不满足强度要求 |
409 | email_taken | 邮箱已注册 |
POST /api/auth/login
| 参数 | 类型 | 必填 |
|---|---|---|
email | string | 是 |
password | string | 是 |
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(并且账号不存在时也会执行一次哈希计算来拉平响应时间),因此该接口不能用于探测某个邮箱是否已注册。
| HTTP | error | 触发条件 |
|---|---|---|
401 | invalid_credentials | 邮箱或密码不正确 |
403 | account_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 }