2015-10-06 00:13:51 -07:00
|
|
|
export function ifNoUserRedirectTo(url, message) {
|
2015-06-20 11:43:12 -07:00
|
|
|
return function(req, res, next) {
|
2015-10-06 00:13:51 -07:00
|
|
|
const { path } = req;
|
2015-06-20 11:43:12 -07:00
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
2015-10-06 00:13:51 -07:00
|
|
|
|
|
|
|
req.flash('errors', {
|
|
|
|
msg: message || `You must be signed to go to ${path}`
|
|
|
|
});
|
|
|
|
|
2015-06-20 11:43:12 -07:00
|
|
|
return res.redirect(url);
|
|
|
|
};
|
2015-10-02 11:47:36 -07:00
|
|
|
}
|
2015-06-20 11:43:12 -07:00
|
|
|
|
2015-10-02 11:47:36 -07:00
|
|
|
export function ifNoUserSend(sendThis) {
|
2015-06-22 16:43:31 -07:00
|
|
|
return function(req, res, next) {
|
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return res.status(200).send(sendThis);
|
|
|
|
};
|
2015-10-02 11:47:36 -07:00
|
|
|
}
|
2015-08-18 19:48:42 -07:00
|
|
|
|
2015-10-02 11:47:36 -07:00
|
|
|
export function ifNoUser401(req, res, next) {
|
2015-08-18 19:48:42 -07:00
|
|
|
if (req.user) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return res.status(401).end();
|
2015-10-02 11:47:36 -07:00
|
|
|
}
|