# 删除当前账号

验证身份后永久删除当前账号及关联账号记录。

POST `/api/account/delete`

- **认证** 控制台会话 Cookie。
- **成功状态** `200`

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `password` | string | `body` | 否 | 有密码的账号必须提交当前密码。 |
| `confirmation` | DELETE | `body` | 否 | 无密码账号必须传入 DELETE。 |

## 请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

**cURL**

```bash
curl -i -X POST 'https://social2api.com/api/account/delete' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://social2api.com' \
  --data-binary '{
  "password": "<current password>"
}'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/api/account/delete",
    method="POST",
    headers={
        "Content-Type": "application/json",
        "Origin": "https://social2api.com",
    },
    data="{\"password\":\"<current password>\"}".encode("utf-8"),
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/api/account/delete", {
  method: "POST",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "password": "<current password>"
  }),
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "account": null
}
```

**错误示例**

```json
{
  "error": "账户服务暂不可用，请稍后重试。"
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `account` | null | 退出登录后的状态。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `400` | 请求格式或字段无效。 |
| `401` | 凭据无效或已过期。 |
| `403` | 浏览器来源校验失败，或免密码账号需重新登录验证身份。 |
| `409` | 账户状态在请求期间变更，请重新登录。 |
| `405` | 请求方法不受支持。 |
| `413` | 请求体超出 4,096 字节。 |
| `415` | 需要 application/json 请求体。 |
| `429` | 尝试次数过多。根据 Retry-After 的秒数再试。 |
| `500` | 账户服务暂时不可用。 |
| `503` | 此部署未配置该控制台服务。 |

## 使用细节

-   账户写请求来自站点同源页面。跨站请求由服务器拒绝。
-   JSON 请求体最多 4,096 字节。
-   撤销当前会话并通过 Set-Cookie 清除浏览器 Cookie。
-   无密码账号要求已验证邮箱，并在最近 10 分钟内登录。

## 同组接口

-   [GET 读取登录会话](<https://social2api.com/docs/api/account-session/>)
-   [POST 注册账号](<https://social2api.com/docs/api/account-register/>)
-   [POST 登录账号](<https://social2api.com/docs/api/account-login/>)
-   [POST 退出登录](<https://social2api.com/docs/api/account-logout/>)
-   [PATCH 更新账号显示名](<https://social2api.com/docs/api/account-profile/>)
-   [PATCH 更新账号语言](<https://social2api.com/docs/api/account-preferences/>)
-   [POST 设置或修改密码](<https://social2api.com/docs/api/account-password/>)
-   [POST 发送邮箱验证码](<https://social2api.com/docs/api/account-otp-request/>)
-   [POST 验证邮箱验证码](<https://social2api.com/docs/api/account-otp-verify/>)
-   [GET 开始 Google 登录](<https://social2api.com/docs/api/account-google/>)
-   [GET 处理 Google 登录回调](<https://social2api.com/docs/api/account-google-callback/>)

规范页面：<https://social2api.com/docs/api/account-delete/>
