Create authorizedByAPIKey middleware
This commit is contained in:
parent
79233471c6
commit
fda7661dad
@ -198,6 +198,26 @@ NamedMapsAdminController.prototype.list = function(req, res, next) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) {
|
||||||
|
return function authorizedByAPIKeyMiddleware (req, res, next) {
|
||||||
|
const { user } = res.locals;
|
||||||
|
|
||||||
|
this.authApi.authorizedByAPIKey(user, req, (err, authenticated) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!authenticated) {
|
||||||
|
const error = new Error(`Only authenticated user can ${action} templated maps`);
|
||||||
|
error.http_status = 403;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}.bind(this);
|
||||||
|
};
|
||||||
|
|
||||||
function finishFn(controller, req, res, description, status, next) {
|
function finishFn(controller, req, res, description, status, next) {
|
||||||
return function finish(err, body){
|
return function finish(err, body){
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user