tenant-check.js 514 B

1234567891011121314
  1. 'use strict';
  2. const _ = require('lodash');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. module.exports = options => {
  5. return async function tenantCheck(ctx, next) {
  6. const request = ctx.request;
  7. if (request.method !== 'GET') {
  8. const tenant = _.get(request, 'header.x-tenant');
  9. // 该中间只能通过master的权限进行增删改
  10. if (tenant !== 'master') throw new BusinessError(ErrorCode.ACCESS_DENIED, '您没有访问的权限!');
  11. }
  12. await next();
  13. };
  14. };