How to end a session in ExpressJS

前端 未结 9 863
小鲜肉
小鲜肉 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:02

    The question didn't clarify what type of session store was being used. Both answers seem to be correct.

    For cookie based sessions:

    From http://expressjs.com/api.html#cookieSession

    req.session = null // Deletes the cookie.
    

    For Redis, etc based sessions:

    req.session.destroy // Deletes the session in the database.
    

提交回复
热议问题