You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
533 B
JavaScript

const db = require('../../db')
const sessionMiddleware = (req, res, next)=>{
(async ()=>{
let session = await db.session.validate(req.session.uuid);
if(!session)
return req.session.uuid = null;
// Update last active
session = await db.session.update(req.session.uuid);
// Attach updated session object to request
req.sessionObj = session;
if(session){
req.user = session.user;
req.cart = session.cart;
}
})()
.then(next).catch(next);
}
module.exports = sessionMiddleware;