mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-04-04 16:16:23 -05:00
28 lines
575 B
JavaScript
28 lines
575 B
JavaScript
/*
|
|
|
|
admin-authentication.js -
|
|
Middleware file for authentication checking
|
|
|
|
*/
|
|
|
|
// imports
|
|
const apiHelper = require('../helpers/api');
|
|
|
|
// 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 {
|
|
apiHelper.sendApiAuthError(res);
|
|
}
|
|
}
|
|
|
|
// middleware to use if authentication
|
|
function authenticationOptional(req, res, next) {
|
|
return next();
|
|
}
|
|
|
|
module.exports = {
|
|
adminAuthenticationRequired,
|
|
authenticationOptional
|
|
}; |