'Express.js session lost after about 3min (I Have the same issue ) [duplicate]
I am facing the same issue like this question: Express.js session lost after about 3min
But can't find any solution yet.
My Session Code:
app.use(
session({
secret: 'secret',
resave: false,
saveUninitialized: false,
cookie: {secure: true, maxAge: 1000*60*60*24}
})
);
Solution 1:[1]
I solve this issue by using express-mysql-session package.
//import
const session = require('express-session');
const MySQLStore = require('express-mysql-session')(session);
let options = {
host: process.env.hostNameDB,
port: 3306,
user: process.env.userNameDB,
password: process.env.passwordDB,
database: process.env.databaseName,
expiration: 1000 * 60 * 60 * 24,
clearExpired: true,
checkExpirationInterval: 1000 * 60 * 60 * 24, //per day db cleaning
};
let sessionStore = new MySQLStore(options);
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: sessionStore,
resave: false,
saveUninitialized: false
}));
By using this package you can store your session data properly and then it will delete the data from DB when checkExpirationInterval is crossed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sabiul Sabit |
