# logout()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/auth/logout/
Language: zh

`api.auth.logout() → Promise<{ ok: true }>`

结束客户端使用的会话。 密钥未动, 因此下个调用开始新调用 。

Status: POST /api/auth/logout · free · this session only

## 返回值 {#returns}

```javascript
{ ok: true }
```

没有什么可以传递的:会话是从您已经发送的牌子上识别的。 它的刷新牌子停止在同一时刻更新—— 这不是一个以后过期的牌子, 而是结束的会话。

## 下次电话发生什么 {#after}

缓存的标记不再被接受, 刷新失败, 键被交换。 您的代码在新的会话下继续工作。 很少有人会这样叫它 `logout()` 仔细想想,你们想看哪一个。

```javascript
await api.auth.logout();

await api.getUser();   // works — a different session now
```

| 想要什么 | 调用 |
| --- | --- |
| 停止为本届会议的进程 | api.auth.logout() |
| 此密钥可以停止工作 | api.keys.revoke(id) |
| 另一要签名的设备 | api.auth.revokeSession(id) |

## 两次调用它 {#idempotent}

第二次是会议之下发出的呼吁,第一次是呼吁引起的,因此,它回答了 `{ ok: true }` 你们应当使那段经典成为最后的,那不是错误,也不是断绝的。无论会议是何时举行的,每件事都以结束。

## 当那经是正经的时候, {#when}

- 一份短命的工作已经完成了,你宁愿不留下一个会议 活着在它后面。
- 显示访客外出 其会话是访客的 而不是您的服务器的
- 一台机器被退役——同时取消它所拥有的钥匙。

当它不是:作为长期服务器的清理。在那里,会话让你的电话变得便宜—— 结束每次关闭就意味着在下一靴子上再次交换钥匙。

### 结束工作会 干净干净地结束工作

```javascript
try {
  await doTheWork(api);
} finally {
  // Best effort: the work is done either way, and a failed logout
  // must not become the error the caller sees.
  await api.auth.logout().catch(() => {});
}
```

> **在浏览器中, 清除隐藏的东西**
>
> 会话被保存在页面自己的仓库中。 结束服务器端的服务器端留下一个死条目, 下次调用时会尝试换换。 替换客户端, 或者清除商店 。

```javascript
await api.auth.logout();

// The page keeps its own copy. Clear it, or the next call tries a dead token first.
await myStore.clear();
```

- [revokeSession()](/zh/sdk/ref/auth/revoke-session): 结束不是这个会议。
- [api.keys.revoke()](/zh/sdk/ref/keys/revoke): 阻止背后的钥匙

```python
{"ok": True}
```

```python
api.auth.logout()

api.get_user()   # works — a different session now
```

```python
from iagenify import IaGenifyError

try:
    do_the_work(api)
finally:
    # Best effort: the work is done either way, and a failed logout
    # must not become the error the caller sees.
    try:
        api.auth.logout()
    except IaGenifyError:
        pass
```

```python
api.auth.logout()

# A custom store keeps its own copy. Clear it, or the next call tries a dead token first.
my_store.clear()
```
