import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
  constructor() {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // 🔥 reads Bearer token
      ignoreExpiration: false,
      secretOrKey: process.env.JWT_SECRET, // ⚠️ use env later
    });
  }

  async validate(payload: any) {
    return payload; // attached to req.user
  }
}