import { Inject , Injectable } from "@nestjs/common" ; import * as passport from "passport" ; import { ExtractJwt , Strategy } from "passport-jwt" ; import { AuthService } from "./services/auth.service" ; import { AuthDiToken } from "./auth.di" ; import { Config , ConfigDiToken } from "../config" ; @ Injectable ( ) export class JwtStrategy extends Strategy { public constructor ( @ Inject ( AuthDiToken . AUTH_SERVICE ) private readonly authService , @ Inject ( ConfigDiToken . CONFIG ) private readonly config ) { super ( { jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) , passReqToCallback : true , secretOrKey : AuthService . SECRET , } , async ( req , payload , next ) => await this . verify ( req , payload , next ) ) ; passport . use ( this ) ; } public verify ( req , payload , done ) { done ( null , payload ) ; } }