fix cannot read property id of user durring upvote

post to upvote without auth returns 401
This commit is contained in:
Berkeley Martinez
2015-08-18 19:48:42 -07:00
parent 8c803281f6
commit 0128829d11
2 changed files with 13 additions and 5 deletions

View File

@ -12,12 +12,12 @@ exports.userMigration = function userMigration(req, res, next) {
if (!req.user || req.user.completedChallenges.length !== 0) {
return next();
}
req.user.completedChallenges = R.filter(function (elem) {
req.user.completedChallenges = R.filter(function(elem) {
// getting rid of undefined
return elem;
}, R.concat(
req.user.completedCoursewares,
req.user.completedBonfires.map(function (bonfire) {
req.user.completedBonfires.map(function(bonfire) {
return ({
completedDate: bonfire.completedDate,
id: bonfire.id,
@ -51,3 +51,10 @@ exports.ifNoUserSend = function ifNoUserSend(sendThis) {
return res.status(200).send(sendThis);
};
};
exports.ifNoUser401 = function ifNoUser401(req, res, next) {
if (req.user) {
return next();
}
return res.status(401).end();
};