Property does not exist on type using koa parser to read body parameters

504 Views Asked by At

I'm trying to use koa-bodyparser to read post parameters:

router.use(koaBody(), async (ctx: Context, next: () => Promise<any>) => {
    if (
     (!ctx.request.body || ctx.request.body.token != adminToken)
    ) {
      ctx.throw(HttpStatus.UNAUTHORIZED, 'Authorization failed');
    } else {
      next();
    }
  });

Getting a type error when accessing ctx.request.body.token.

0

There are 0 best solutions below