Files
habitica/website/server/middlewares/ensureAccessRight.js
2019-10-10 20:11:50 +02:00

25 lines
486 B
JavaScript

import {
NotAuthorized,
} from '../libs/errors';
import apiError from '../libs/apiError';
export function ensureAdmin (req, res, next) {
const { user } = res.locals;
if (!user.contributor.admin) {
return next(new NotAuthorized(res.t('noAdminAccess')));
}
return next();
}
export function ensureSudo (req, res, next) {
const { user } = res.locals;
if (!user.contributor.sudo) {
return next(new NotAuthorized(apiError('noSudoAccess')));
}
return next();
}