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.
21 lines
481 B
JavaScript
21 lines
481 B
JavaScript
const db = require('../../db')
|
|
|
|
const sessionMiddleware = (req, res, next)=>{
|
|
(async ()=>{
|
|
let session = await db.session.validate(req.session.uuid);
|
|
|
|
if(!session) return;
|
|
|
|
// Update last active
|
|
session = await db.session.update(req.session.uuid);
|
|
// Attach updated session object to request
|
|
req.sessionObj = session;
|
|
|
|
if(session && session.user)
|
|
req.user = session.user;
|
|
})()
|
|
.then(next).catch(next);
|
|
}
|
|
|
|
module.exports = sessionMiddleware;
|