import { Strategy , ExtractJwt } from 'passport-jwt' ; import { Injectable } from '@nestjs/common' ; import { PassportStrategy } from '@nestjs/passport' ; import { jwtConstants } from './constants' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( ) { super ( { jwtFromRequest : ExtractJwt . fromHeader ( 'token' ) , ignoreExpiration : false , secretOrKey : jwtConstants . secret , } ) ; } async validate ( payload ) { return { userId : payload . sub , username : payload . username } ; } }