enables loading config within webpack
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user