如何在ExpressJS中结束会话 [英] How to end a session in ExpressJS

查看:70
本文介绍了如何在ExpressJS中结束会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这必须埋藏在文档中的某个地方,但我找不到.

I feel like this has to be buried somewhere in the documentation, but I can't find it.

您如何关闭或结束或终止ExpressJS中的会话(无论如何)?

How do you close or end or kill (whatever) a session in ExpressJS?

推荐答案

Express 4.x更新的答案

会话处理不再内置于Express中.此答案涉及标准会话模块: https://github.com/expressjs/session

要清除会话数据,只需使用:

To clear the session data, simply use:

req.session.destroy();

文档对此没有多大用处.它说:

The documentation is a bit useless on this. It says:

销毁会话,删除req.session,将在下一个请求中重新生成. req.session.destroy(function(err) { // cannot access session here })

Destroys the session, removing req.session, will be re-generated next request. req.session.destroy(function(err) { // cannot access session here })

这不是不是,这意味着当前会话将在下一个请求时重新加载.这意味着将在下次请求时在您的会话存储中创建一个干净的空会话. (大概会话ID并没有改变,但是我还没有测试.)

This does not mean that the current session will be re-loaded on the next request. It means that a clean empty session will be created in your session store on next request. (Presumably the session ID isn't changing, but I have not tested that.)

这篇关于如何在ExpressJS中结束会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆