import { Injectable } from '@nestjs/common' ; import { ConfigService } from '@nestjs/config' ; import { PassportStrategy } from '@nestjs/passport' ; import { ExtractJwt , Strategy } from 'passport-jwt' ; import type { JwtPayload , Payload } from '../auth.interface' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( config ) { super ( { jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) , ignoreExpiration : false , secretOrKey : config . get ( 'jwtSecret' ) , } ) ; } public validate ( payload ) { return { userId : payload . sub , username : payload . username , roles : payload . roles } ; } }