import { Injectable, UnauthorizedException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; @Injectable() export class PortalJwtStrategy extends PassportStrategy(Strategy, 'portal-jwt') { constructor(config: ConfigService) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), ignoreExpiration: false, secretOrKey: config.get('JWT_SECRET') || 'fallback', }); } validate(payload: any) { if (payload.type !== 'portal') { throw new UnauthorizedException('Invalid token type'); } return { sub: payload.sub, tenantId: payload.tenantId, type: 'portal' }; } }