• This project
    • Loading...
  • Sign in

张泽世 / yohobuywap-node · Files

Go to a project

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Pipelines 0
  • Builds 0
  • Graphs
  • Milestones
  • Issues 0
  • Merge Requests 0
  • Members
  • Labels
  • Wiki
  • Forks
  • Network
  • Create a new issue
  • yohobuywap-node
  • doraemon
  • middleware
  • auth.js
  • 登录状态判断中间件
    9c972a40
    by yyq
    2016-06-28 13:22:18 +0800  
    Browse Files
auth.js 482 Bytes
Raw Blame History Permalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/**
 * 登录判断
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2016/4/25
 */
'use strict';

const helpers = global.yoho.helpers;

module.exports = (req, res, next) => {
    if (!req.user.uid) {
        if (req.xhr) {
            return res.json({
                code: 400,
                message: '抱歉,您暂未登录!'
            });
        }

        res.redirect(helpers.urlFormat('/signin.html', {
            refer: req.originalUrl
        }));
    }

    next();
};