import { Injectable , UnauthorizedException } from '@nestjs/common' ; import { PassportStrategy } from '@nestjs/passport' ; import { ExtractJwt , Strategy } from 'passport-jwt' ; import { ConfigurationService } from '../../shared/configuration/configuration.service' ; import { JwtPayload } from '../jwt-payload' ; import { TokenService } from '../token/token.service' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( private readonly tokenService , configurationService ) { super ( { jwtFromRequest : ExtractJwt . fromExtractors ( [ ExtractJwt . fromAuthHeaderAsBearerToken ( ) , ExtractJwt . fromUrlQueryParameter ( 'access_token' ) , ] ) , secretOrKey : configurationService . JWT . Key , passReqToCallback : true , } ) ; } async validate ( payload ) { const result = await this . tokenService . validatePayload ( payload ) ; if ( ! result ) { throw new UnauthorizedException ( ) ; } return result ; } }