所以我在Koa中有这个功能,基本上检查用户是否可以访问特定路由 .

exports.requireRole = async role =>
  async (ctx, next) => {
    const { user } = ctx.state.user;
    try {
      const foundUser = await User.findById(user.id);
      // If the user couldn't be found, return an error
      if (!foundUser) {
        ctx.status = 404;
        ctx.body = { errors: [{ error: ERRORS.USER_NOT_FOUND }] };
      } else {
        // Otherwise, continue checking role
        if (getRole(user.role) >= getRole(role)) {
          await next();
        }

        ctx.status = 403;
        ctx.body = { errors: [{ error: ERRORS.NO_PERMISSION }] };
      }
    } catch (err) {
      ctx.throw(500, err);
    }
  };

我想将它用作中间件:

router.delete('/:id', combine([jwtAuth, requireRole(ROLES.ADMIN)]), deleteUser);

但后来我得到一个错误说:

middleware must be a function not object

只有当我尝试将参数传递给它时才会发生这种情况 .

我在这做错了什么?