enables loading config within webpack

This commit is contained in:
James
2020-01-05 18:16:19 -05:00
parent 219743228d
commit 4bf0ff2b05
16 changed files with 81 additions and 100 deletions

View File

@@ -1,11 +1,12 @@
import HttpStatus from 'http-status';
const HttpStatus = require('http-status');
/**
* authorize a request by comparing the current user with one or more roles
* @param roles
* @returns {Function}
*/
export default function checkRoleMiddleware(...roles) {
const checkRoleMiddleware = (...roles) => {
return (req, res, next) => {
if (!req.user) {
res.status(HttpStatus.UNAUTHORIZED)
@@ -17,4 +18,6 @@ export default function checkRoleMiddleware(...roles) {
next();
}
};
}
};
module.exports = checkRoleMiddleware;

View File

@@ -30,19 +30,17 @@ const authRoutes = (userConfig, User) => {
if (userConfig.auth.registration) {
router
.route(`${userConfig.slug}/register`) // TODO: not sure how to incorporate url params like `:pageId`
.post(userConfig.auth.registrationValidation, auth.register);
.post(auth.register);
router
.route('/first-register')
.post(userConfig.auth.registrationValidation,
(req, res, next) => {
User.countDocuments({}, (err, count) => {
if (err) res.status(500).json({ error: err });
if (count >= 1) return res.status(403).json({ initialized: true });
next();
});
},
auth.register);
.post((req, res, next) => {
User.countDocuments({}, (err, count) => {
if (err) res.status(500).json({ error: err });
if (count >= 1) return res.status(403).json({ initialized: true });
next();
});
}, auth.register);
}
return router;