-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set initial maxAge #175
base: master
Are you sure you want to change the base?
Set initial maxAge #175
Conversation
2 similar comments
There's logic in Lines 290 to 307 in 10bb122
const ONE_DAY = 24 * 60 * 60 * 1000; |
@jmitchell38488 yes but Lines 241 to 250 in 10bb122
plus my screenshot clearly shows that session's max age is not set. |
What's your option config? |
@jmitchell38488 there's no config. why don't you just try it for yourself and see |
setup import Koa from 'koa'
import { aqt } from 'rqt'
import session from 'koa-session'
const koa = new Koa()
const s = session(koa, {
signed: false,
})
koa.use(s)
koa.use((ctx, next) => {
if (ctx.path == '/max-age') {
ctx.session.maxAge = 60 * 60 * 1000
}
if (ctx.path == '/confirm') {
ctx.session.user = 'update'
} else {
ctx.session.user = 'hello'
}
ctx.body = '# ' + ctx.path
}) test koa.listen(async function() {
const a = 'http://localhost:' + this.address().port
let res
res = await aqt(a)
log(res)
res = await aqt(a + '/max-age')
const { headers: { 'set-cookie': setCookie } } = res
log(res)
res = await aqt(a + '/test', {
headers: { cookie: setCookie },
})
// console.log(res)
log(res)
res = await aqt(a + '/confirm')
log(res)
this.close()
})
const log = (res) => {
const { body, headers: { 'set-cookie': cookie = [] } } = res
console.log(body)
console.log(cookie.map(s => s.split('; ').join('\n ')).join('\n'))
} output
# /
koa:sess=eyJ1c2VyIjoiaGVsbG8iLCJfZXhwaXJlIjoxNTc3MDY4Nzk1NjA5LCJfbWF4QWdlIjo4NjQwMDAwMH0=
path=/
httponly
# /max-age
koa:sess=eyJ1c2VyIjoiaGVsbG8iLCJfZXhwaXJlIjoxNTc2OTg1OTk1NjcyLCJfbWF4QWdlIjozNjAwMDAwfQ==
path=/
expires=Sun, 22 Dec 2019 03:39:55 GMT
httponly
# /test
# /confirm
koa:sess=eyJ1c2VyIjoidXBkYXRlIiwiX2V4cGlyZSI6MTU3NzA2ODc5NTY5NCwiX21heEFnZSI6ODY0MDAwMDB9
path=/
httponly |
The initial cookie that this middleware drops does not have
expires
, becausemaxAge
is never set in properties. It is only set later when decoding the cookie, and only if it has been updated, therefore if no data was updated, the cookie is always limited to the session.