> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ariacompute.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /api/auth/login — 使用邮箱或手机号登录

> 用邮箱或手机号标识加密码换取会话 JWT。账户启用两步验证时会处理 2FA 挑战。

使用邮箱地址或手机号与密码登录。返回会话 JWT，你可在后续用户作用域请求中作为 `Authorization: Bearer` 使用。若账户启用了 2FA，响应会是一个挑战，你必须用 `POST /api/auth/2fa/verify` 完成它。

**方法：** `POST` **路径：** `/api/auth/login` **认证：** 无

## 请求

<ParamField body="identifier" type="string" required>
  邮箱地址或 E.164 格式的手机号。
</ParamField>

<ParamField body="password" type="string" required>
  账户密码。
</ParamField>

## 响应

<ResponseField name="token" type="string">
  会话 JWT。在后续请求中作为 `Authorization: Bearer` 发送。
</ResponseField>

<ResponseField name="user" type="object">
  已登录用户档案。

  <Expandable>
    <ResponseField name="id" type="string">
      稳定的用户标识。
    </ResponseField>

    <ResponseField name="email" type="string">
      邮箱（若已设置）。
    </ResponseField>

    <ResponseField name="phone" type="string">
      手机号（若已设置）。
    </ResponseField>

    <ResponseField name="name" type="string">
      显示名称。
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 时间戳。
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="two_factor_required" type="boolean">
  当 2FA 启用时存在且为 `true`。此时 `token` 是一个短时效挑战令牌；请调用 `POST /api/auth/2fa/verify` 完成登录。
</ResponseField>

## 示例

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://ariacompute.cn/api/auth/login \
    -H "Content-Type: application/json" \
    -d '{"identifier": "you@example.com", "password": "..."}'
  ```
</CodeGroup>

```json theme={null}
{
  "token": "eyJhbGciOi...",
  "user": {
    "id": "usr_01H...",
    "email": "you@example.com",
    "name": "Jane",
    "created_at": "2026-01-14T09:30:00Z"
  }
}
```

## 错误

| 状态    | 含义                            |
| ----- | ----------------------------- |
| `400` | 缺失 `identifier` 或 `password`。 |
| `401` | 凭证错误。                         |
| `429` | 失败尝试过多。                       |
