import { ExtractJwt , Strategy } from 'passport-jwt' ; import { AuthService } from '../auth.service' ; import { PassportStrategy } from '@nestjs/passport' ; import { Request } from 'express' ; import { use } from 'passport' ; import { Injectable , UnauthorizedException } from '@nestjs/common' ; import { JwtPayload } from '../interfaces/jwt-payload.interface' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( private readonly authService ) { super ( { jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) , secretOrKey : 'ILovePokemon' , } ) ; } async validate ( req , payload , done ) { const user = await this . authService . validateUser ( payload ) ; if ( ! user ) { return done ( new UnauthorizedException ( ) , false ) ; } done ( null , user ) ; } }