stockadvisor / api /src /auth /jwt.strategy.ts
Bibhu Mishra
Add GitHub Actions CI/CD, HF Space deployment, market hours guard, and static serving
abc493d
Raw
History Blame Contribute Delete
630 Bytes
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(cfg: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: cfg.get<string>('JWT_SECRET') ?? 'stockadvisor-secret',
});
}
async validate(payload: { sub: number; email: string; role: string }) {
return { id: payload.sub, email: payload.email, role: payload.role };
}
}