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;