Authored by htoooth

fix auth bug

... ... @@ -12,18 +12,20 @@ const helpers = global.yoho.helpers;
module.exports = (req, res, next) => {
let refer = req.method === 'GET' ? req.get('Referer') : '';
let loginUrl = helpers.urlFormat('/passport/login', {refer: refer});
let loginAPI = helpers.urlFormat('/passport/login', {refer: refer});
let loginPage = helpers.urlFormat('/passport/login', {refer: req.fullUrl()});
if (_.isEmpty(req.user) || !req.user.uid) {
if (req.xhr) {
return res.json({
code: 400,
message: '抱歉,您暂未登录!',
data: {refer: loginUrl}
data: {refer: loginAPI}
});
}
return res.redirect(loginUrl);
return res.redirect(loginPage);
}
next();
};
... ...