eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.9k stars 1.82k forks source link

redis存储session, 如何设置过期时间, 让浏览器关闭之后让session失效 #2926

Closed xiaoshuimao closed 6 years ago

xiaoshuimao commented 6 years ago
config.session = {
    //maxAge: 10 * 60 * 1000 , // ms
    maxAge: 'session',
    key: 'EGG_SESS',
    httpOnly: true,
        encrypt: true,
}

我这样设置并没有效果, 需要其他方式来实现么?

egg-bot commented 6 years ago

Translation of this issue:


redisStorage session, how to set the expiration time, let the browser expire after the browser is closed

Config.session = {
//maxAge: 10 * 60 * 1000 , // ms
maxAge: 'session',
Key: 'EGG_SESS',
httpOnly: true,
        Encrypt: true,
}

I have no effect in this setting. Do you need other ways to achieve it?

whxaxes commented 6 years ago

就是这么设置 maxAge: 'session' ,给个能稳定复现的 repo

whxaxes commented 6 years ago

貌似是已知 bug : https://github.com/koajs/session/issues/133

xiaoshuimao commented 6 years ago

@whxaxes 感谢

whxaxes commented 6 years ago

看了一下代码,看到 @dead-horse 当初做了这个更改 https://github.com/koajs/session/commit/b976b10212f522b675711badb7ce1bc9a909d19d ,改成了每次实例化的 context session 实例用的都是同个 opts,而在 https://github.com/koajs/session/blob/master/lib/context.js#L293 中又对 maxAge 做了更改,当 maxAge 为 session 的时候就把 opts.maxAge 改成了 undefined,就导致了这个问题 .... @dead-horse 是否得改回 assign 去?

dead-horse commented 6 years ago

@whxaxes 👍 可以提个 PR

whxaxes commented 6 years ago

@dead-horse 提了:https://github.com/koajs/session/pull/136