12345678910111213141516171819202122 |
- 'use strict';
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- module.exports = (options, app) => {
- return async (ctx, next) => {
- const url = ctx.request.url;
- if (url.includes('/y/')) await next();
- else {
- const { authorization, dtype } = ctx.request.header;
- if (!dtype || dtype !== 'pc') await next();
- else if (authorization) {
- let user = decodeURI(authorization);
- if (user) {
- user = JSON.parse(user);
- if (user.type === '4') await next();
- const res = await ctx.service.yunjiuye.checkYjyLogin(user.id);
- if (!res) throw new BusinessError(ErrorCode.NOT_LOGIN);
- else await next();
- }
- } else throw new BusinessError(ErrorCode.NOT_LOGIN);
- }
- };
- };
|