Languages

Express.js - Cookie maxAge TypeError

3 points
Asked by:
Majid-Hajibaba
402

How can I fix this problem? Should I specify originalMaxAge instead of maxAge?

TypeError: Cannot read property 'originalMaxAge' of undefined

My session implementation:

app.use(
  session({
    name: process.env.SESSION_NAME,
    resave: false,
    saveUninitialized: false,
    secret: process.env.SESSION_SECRET,
    cookie: {
      maxAge: Number(process.env.SESSION_MAX_AGE),
    },
  })
);
1 answer
3 points
Answered by:
Majid-Hajibaba
402

The problem is that you store cookie maxAge value in the .env file. It returns SESSION_MAX_AGE variable as a string instead of a number which causes the error.

Fixed this by converting SESSION_MAX_AGE to a number.

cookie: {
      maxAge: Number(process.env.SESSION_MAX_AGE),
    }
0 comments Add comment
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join