Knex Connection clears session table with server restart.
th-m opened this issue · 0 comments
th-m commented
code
const session = require('express-session');
const KnexSessionStore = require('connect-session-knex')(session);
const store = new KnexSessionStore({
knex: Model.knex,
tablename: 'sessions',
clearInterval: 3600000
})
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 30000 // 2 seconds for testing
},
store: store}));
app.use(passport.initialize());
app.use(passport.session());
function authenticationMiddleware(){
return (req, res, next) => {
console.log(req.session);
console.log(`req.session.passport.user:`, req.session.passport);
if(req.isAuthenticated()) return next();
return res.status(403).json({status:"failed", message: "Could not authenticate user."});
console.log("failed sucker");
}
}
For some reason the database info will not persist after the server is being restarted. I am not sure if this is a configuration error on my part of it is a bug in the code.