koajs / session

Simple session middleware for koa
MIT License
901 stars 113 forks source link

关闭浏览器后,session无法失效 #104

Closed baiej214 closed 6 years ago

baiej214 commented 6 years ago

@dead-horse 你好,请问如何配置session,才能实现关闭浏览器session就失效呢?目前我找了几个方法,要么是一天,要么是指定是毫秒时长。

fengmk2 commented 6 years ago

https://github.com/koajs/session/blob/master/lib/context.js#L249

set maxAge to session, see the readme first please.

const CONFIG = {
  key: 'koa:sess', /** (string) cookie key (default is koa:sess) */
  /** (number || 'session') maxAge in ms (default is 1 days) */
  /** 'session' will result in a cookie that expires when session/browser is closed */
  /** Warning: If a session cookie is stolen, this cookie will never expire */
  maxAge: 86400000,
  overwrite: true, /** (boolean) can overwrite or not (default true) */
  httpOnly: true, /** (boolean) httpOnly or not (default true) */
  signed: true, /** (boolean) signed or not (default true) */
  rolling: false, /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. default is false **/
};