auth.js
473 Bytes
/**
* 登录判断
* @author: leo<qi.li@yoho.cn>
* @date: 2017/6/23
*/
'use strict';
const _ = require('lodash');
module.exports = (req, res, next) => {
const userId = _.get(req.session, 'user.id', 0);
if (!userId) {
if (req.xhr) {
return res.json({
code: 401,
message: '抱歉,您暂未验证'
});
} else {
return res.render('error/404');
}
}
next();
};