import { Strategy } from 'passport-jwt'; import { PassportStrategy } from '@nestjs/passport'; import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { FastifyRequest } from 'fastify'; @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor(private configService: ConfigService) { super({ jwtFromRequest: (request: FastifyRequest) => { const authHeader = request.headers.authorization; if (authHeader && authHeader.startsWith('Bearer ')) { return authHeader.substring(7); } return null; }, ignoreExpiration: false, secretOrKey: configService.get('JWT_SECRET', 'devsecret'), }); } async validate(payload: any) { return { userId: payload.sub, email: payload.email, tenantId: payload.tenantId, }; } }