Nest.js cannot pass parameter to controller

Viewed 27

In my middleware, Im decoding the request token and extract msisdn from it to pass to the controllers as custom decorator.But i got this error

Property 'decorate' does not exist on type 'Request'.

auth.midleware.ts

export class AuthMiddleware implements NestMiddleware {
  constructor(
    private readonly commonHelper: Common,
  ) {}

  async use(req: Request, res: Response, next: NextFunction) {
    const token = req?.headers?.authorization;
    try {
    
        const response = await this.commonHelper.verifyToken({
          token,
        });
        
        if (response.statusCode === HttpStatus.OK) {
        
          req.decorate = {  // Property 'decorate' does not exist on type 'Request<ParamsDictionary>'.
            msisdn: response?.data?.msisdn,
          };
          
          next();
          
        } else {
          
        }
     
    } catch (error) {
    
    }
  }
}
0 Answers
Related