import { ExtractJwt, Strategy } from 'passport-jwt'; import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ConfigService } from '@nestjs/config'; export interface JwtPayload { sub: string; username: string; role: 'admin' | 'player'; } @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor(config: ConfigService) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), ignoreExpiration: false, secretOrKey: config.get('JWT_ACCESS_SECRET'), }); } async validate(payload: JwtPayload): Promise { if (!payload?.sub) throw new UnauthorizedException(); return payload; } }