import { Injectable } from '@nestjs/common'; import { AuthService, JwtPayload } from './auth.service'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; import { ConfigService } from '../config/config.service'; @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor( private readonly authService: AuthService, private readonly configService: ConfigService, ) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), secretOrKey: configService.jwtSecret, }); } async validate(payload: JwtPayload) { return await this.authService.validateUser(payload); } }