123456789101112131415161718192021222324252627282930 |
- 'use strict';
- /**
- * [前端用户登录检测]
- * @author szjcomo
- * @createTime 2020-08-03
- * @return {[type]} [description]
- */
- module.exports = options => {
- /**
- * [notFoundHandler 中间件实现]
- * @author szjcomo
- * @createTime 2020-08-03
- * @param {[type]} ctx [description]
- * @param {Function} next [description]
- * @return {[type]} [description]
- */
- return async function webLogin(ctx, next) {
- const token = ctx.request.header.weblogintoken;
- if (token) {
- try {
- const user = ctx.app.jwt.verify(token, options.secret);
- await next();
- } catch (err) {
- return ctx.appJson(ctx.app.szjcomo.appResult('登录时间过期,请重新登录', null, true, 10001));
- }
- } else {
- return ctx.appJson(ctx.app.szjcomo.appResult('未登录,请先登录后再进行数据操作', null, true, 10001));
- }
- };
- };
|