auth.js
492 Bytes
/**
* 登录判断
* @author: TaoHuang
* @date: 2016/7/15
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helper;
const required = (req, res, next) => {
req.getUrl = function() {
return req.protocol + '://' + req.get('host') + req.originalUrl;
};
if (_.isEmpty(req.user) || !req.user.uid) {
return res.redirect(helpers.urlFormat('/passport/login', {refer: req.getUrl()}));
}
next();
};
module.exports = {
required
};