auth.js
458 Bytes
/**
* 登录判断
* @author: TaoHuang
* @date: 2016/7/15
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
module.exports = (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();
};