Session: Cannot read property 'originalMaxAge' of undefined

Created on 4 Nov 2019  路  1Comment  路  Source: expressjs/session

i added originalMaxAge in my cookie and defined it, but i dont think its the way to solve this. is it just me doing something wrong or its something in session.js:59

this.cookie.maxAge = this.cookie.originalMaxAge;
TypeError: Cannot read property 'originalMaxAge' of undefined

Most helpful comment

i added originalMaxAge in my cookie and defined it, but i dont think its the way to solve this. is it just me doing something wrong or its something in session.js:59

this.cookie.maxAge = this.cookie.originalMaxAge;
TypeError: Cannot read property 'originalMaxAge' of undefined

I had the same error when I was setting the cookie.maxAge property to environment variable SESS_EXPIRY while configuring session middleware

app.use(session({
secret:process.env.SECRET,
resave:false,
saveUninitialized:false,
cookie: {
maxAge: process.env.SESS_EXPIRY,
sameSite: true
}
}));

The problem was the .env file was returning SESS_EXPIRY as a string instead of a number and causing the error. Fixed it by parsing SESS_EXPIRY and converting it to a number.

app.use(session({
secret:process.env.SECRET,
resave:false,
saveUninitialized:false,
cookie: {
maxAge: Number(process.env.SESS_EXPIRY),
sameSite: true
}
}));

>All comments

i added originalMaxAge in my cookie and defined it, but i dont think its the way to solve this. is it just me doing something wrong or its something in session.js:59

this.cookie.maxAge = this.cookie.originalMaxAge;
TypeError: Cannot read property 'originalMaxAge' of undefined

I had the same error when I was setting the cookie.maxAge property to environment variable SESS_EXPIRY while configuring session middleware

app.use(session({
secret:process.env.SECRET,
resave:false,
saveUninitialized:false,
cookie: {
maxAge: process.env.SESS_EXPIRY,
sameSite: true
}
}));

The problem was the .env file was returning SESS_EXPIRY as a string instead of a number and causing the error. Fixed it by parsing SESS_EXPIRY and converting it to a number.

app.use(session({
secret:process.env.SECRET,
resave:false,
saveUninitialized:false,
cookie: {
maxAge: Number(process.env.SESS_EXPIRY),
sameSite: true
}
}));

Was this page helpful?
0 / 5 - 0 ratings