cs2-rcon-panel/modules/middleware.js

14 lines
399 B
JavaScript
Raw Normal View History

2023-09-28 07:23:33 +02:00
function is_authenticated(req, res, next) {
if (req.session.user) {
next();
} else {
const accept_header = req.headers['accept'];
if (accept_header && accept_header.includes('text/html')) {
res.redirect('/');
} else {
res.status(401).json({ status: 401, message: 'Unauthorized' });
}
}
}
module.exports = is_authenticated;