checkIsLogin.js 773 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const { BusinessError, ErrorCode } = require('naf-core').Error;
  3. module.exports = (options, app) => {
  4. return async (ctx, next) => {
  5. const url = ctx.request.url;
  6. if (url.includes('/y/')) await next();
  7. else {
  8. const { authorization, dtype } = ctx.request.header;
  9. if (!dtype || dtype !== 'pc') await next();
  10. else if (authorization) {
  11. let user = decodeURI(authorization);
  12. if (user) {
  13. user = JSON.parse(user);
  14. if (user.type === '4') await next();
  15. const res = await ctx.service.yunjiuye.checkYjyLogin(user.id);
  16. if (!res) throw new BusinessError(ErrorCode.NOT_LOGIN);
  17. else await next();
  18. }
  19. } else throw new BusinessError(ErrorCode.NOT_LOGIN);
  20. }
  21. };
  22. };