import { ExtractJwt , Strategy } from 'passport-jwt' ; import { PassportStrategy } from '@nestjs/passport' ; import { Injectable , Inject } from '@nestjs/common' ; import { ConfigService } from '@nestjs/config' ; import { IUser } from '@energyweb/origin-backend-core' ; import { UserService } from '../pods/user/user.service' ; import { IJWTPayload } from './auth.service' ; @ Injectable ( ) export class JwtStrategy extends PassportStrategy ( Strategy ) { constructor ( @ Inject ( ConfigService ) configService , private readonly userService ) { super ( { jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) , ignoreExpiration : false , secretOrKey : configService . get < string > ( 'JWT_SECRET' ) } ) ; } async validate ( payload ) { const user = await this . userService . findByEmail ( payload . email ) ; if ( user ) { return user ; } return null ; } }