title: Nest.js pass variable from middleware to controller
body: <p>I couldn't find a clear way of passing variables from a middleware to a constructure in Nest.js. I'm validating a JWT inside my <code>AuthMiddleware</code> and I want to make this token accessible to the controllers.<br />
  Below is just an extract of my middleware to provide a code sample. I want to make the <code>token</code> accessible inside of my Controllers.</p>
  <pre class="lang-js prettyprint-override"><code>import { Request, Response, NextFunction } from 'express';
  // other imports
  
  @Injectable()
  export class AuthMiddleware implements NestMiddleware {
    async use(req: Request, res: Response, next: NextFunction) {
      const authHeader = req.header('authorization');
  
      if (!authHeader) {
        throw new HttpException('No auth token', HttpStatus.UNAUTHORIZED);
      }
  
      const bearerToken: string[] = authHeader.split(' ');
      const token: string = bearerToken[1];
  
      res.locals.token = token;
    }
  }
  </code></pre>
  <p>I already tried to make the token accessible by changing the <code>res.locals</code> variable but the response object is still empty in my controller.
  This is my controller in which I want to access the token of the middleware:</p>
  <pre class="lang-js prettyprint-override"><code>@Controller('did')
  export default class DidController {
    constructor(private readonly didService: DidService) {}
  
    @Get('verify')
    async verifyDid(@Response() res): Promise&lt;string&gt; {
      console.log(res)
      // {}
      return res;
    }
  </code></pre>