Follow Node.js callback pattern
This commit is contained in:
parent
809c267419
commit
6e4c8a6639
@ -8,11 +8,12 @@ module.exports = function user (metadataBackend) {
|
|||||||
return function userMiddleware (req, res, next) {
|
return function userMiddleware (req, res, next) {
|
||||||
res.locals.user = getUserNameFromRequest(req, cdbRequest);
|
res.locals.user = getUserNameFromRequest(req, cdbRequest);
|
||||||
|
|
||||||
getUserId(metadataBackend, res.locals.user, function (userId) {
|
metadataBackend.getUserId(res.locals.user, (err, userId) => {
|
||||||
if (userId) {
|
if (err || !userId) {
|
||||||
res.locals.userId = userId;
|
return next();
|
||||||
}
|
}
|
||||||
return next();
|
|
||||||
|
res.locals.userId = userId;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -20,12 +21,3 @@ module.exports = function user (metadataBackend) {
|
|||||||
function getUserNameFromRequest (req, cdbRequest) {
|
function getUserNameFromRequest (req, cdbRequest) {
|
||||||
return cdbRequest.userByReq(req);
|
return cdbRequest.userByReq(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserId (metadataBackend, userName, callback) {
|
|
||||||
metadataBackend.getUserId(userName, function (err, userId) {
|
|
||||||
if (err) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
return callback(userId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user