import * as path from 'path' ; require ( 'dotenv' ) . config ( { path : path . resolve ( process . cwd ( ) , 'apps/bootcamp-api/.env' ) } ) ; import { JwtPayload } from './../interfaces/jwt-payload.interface' ; import { Injectable , UnauthorizedException } from '@nestjs/common' ; import { PassportStrategy } from '@nestjs/passport' ; import { Strategy } from 'passport-jwt' ; import { AuthService } from '../auth.service' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( private readonly authService ) { super ( { jwtFromRequest : authService . returnJwtExtractor ( ) , ignoreExpiration : false , secretOrKey : process . env . JWT_SECRET , } ) ; } async validate ( jwtPayload ) { console . log ( 'JwtStrategy::validate::jwtPayload' ) ; console . dir ( jwtPayload ) ; const user = await this . authService . validateUserJwt ( jwtPayload ) ; if ( ! user ) { throw new UnauthorizedException ( ) ; } return user ; } }