# 读取登录会话

检查当前登录状态和当前部署可用的登录方式。

GET `/api/account/session`

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

## 请求参数

此操作无需提交参数。

## 请求示例

**cURL**

```bash
curl -i -X GET 'https://social2api.com/api/account/session'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/api/account/session",
    method="GET",
)
send = urlopen
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/session", {
  method: "GET",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "account": null,
  "methods": {
    "password": true,
    "emailCode": false,
    "google": false
  }
}
```

**错误示例**

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

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `account` | object \| null | 当前操作涉及的账号。 |
| `account.id` | string | 账号 ID。 |
| `account.email` | string | 规范化的邮箱地址。 |
| `account.name` | string | 显示名。 |
| `account.createdAt` | ISO 8601 date-time | 账号创建时间。 |
| `account.emailVerified` | boolean | 邮箱是否通过验证。 |
| `account.hasPassword` | boolean | 该账号是否已设置密码。 |
| `account.preferences` | object | 已存储的账号偏好。 |
| `methods.password` | boolean | 是否支持邮箱密码。 |
| `methods.emailCode` | boolean | 是否支持邮件验证码。 |
| `methods.google` | boolean | 是否支持 Google 登录。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `405` | 请求方法不受支持。 |
| `500` | 账户服务暂时不可用。 |
| `503` | 此部署未配置该控制台服务。 |

## 使用细节

-   未登录时 account 为 null，仍正常返回 200 和 methods。

## 同组接口

-   [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-delete/>)
-   [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-session/>
