freeCodeCamp/server/utils/middleware.js

25 lines
459 B
JavaScript
Raw Normal View History

2015-10-02 18:47:36 +00:00
export function ifNoUserRedirectTo(url) {
2015-06-20 18:43:12 +00:00
return function(req, res, next) {
if (req.user) {
return next();
}
return res.redirect(url);
};
2015-10-02 18:47:36 +00:00
}
2015-06-20 18:43:12 +00:00
2015-10-02 18:47:36 +00:00
export function ifNoUserSend(sendThis) {
return function(req, res, next) {
if (req.user) {
return next();
}
return res.status(200).send(sendThis);
};
2015-10-02 18:47:36 +00:00
}
2015-10-02 18:47:36 +00:00
export function ifNoUser401(req, res, next) {
if (req.user) {
return next();
}
return res.status(401).end();
2015-10-02 18:47:36 +00:00
}