website/middleware/admin-authentication.js
2018-10-13 13:31:33 +02:00

29 lines
614 B
JavaScript

/*
admin-authentication.js -
Middleware file for authentication checking
*/
// imports
const common = require('../helpers/common');
// middleware to use if admin authentication is required
function adminAuthenticationRequired(req, res, next) {
if (req.isAuthenticated() && req.user.role && req.user.role === 'admin') {
return next();
} else {
console.log('sending auth error');
common.sendApiAuthError(req, res);
}
}
// middleware to use if authentication
function authenticationOptional(req, res, next) {
return next();
}
module.exports = {
adminAuthenticationRequired,
authenticationOptional
};