How to end a session in ExpressJS

前端 未结 9 882
小鲜肉
小鲜肉 2020-12-12 15:48

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

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

9条回答
  •  清歌不尽
    2020-12-12 16:04

    Using req.session = null;, won't actually delete the session instance. The most proper solution would be req.session.destroy();, but this is essentially a wrapper for delete req.session;.

    https://github.com/expressjs/session/blob/master/session/session.js

    Session.prototype.destroy = function(fn){
      delete this.req.session;
      this.req.sessionStore.destroy(this.id, fn);
      return this;
    };
    

提交回复
热议问题