title: Nestjs Passport-jwt better Unauthorized strategy
body: <p>just going through docs on authentication in NestJS: <a href="https://docs.nestjs.com/security/authentication" rel="nofollow noreferrer">docs.nestjs.com</a></p>
  <p>Here is the code:</p>
  <pre><code>import { ExtractJwt, Strategy } from 'passport-jwt';  
  import { PassportStrategy } from '@nestjs/passport';
  import { Injectable } from '@nestjs/common';
  import { jwtConstants } from './constants';
  
  @Injectable()
  export class JwtStrategy extends PassportStrategy(Strategy) {
    constructor() {
      super({
        jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
        ignoreExpiration: false,
        secretOrKey: jwtConstants.secret,
      });
    }
  
    async validate(payload: any) {
      return { userId: payload.sub, username: payload.username };
    }
  }
  </code></pre>
  <p>According to docs validate method is called when request contains jwt and that jwt is valid.
  I am wondering is there a callback method for the case when jwt is missing from request header, or jwt is invalid or expired. I would like to return response error with message to client that their  token is expired or missing...</p>
  <p>Thanks</p>