| 1 | import { Injectable } from '@nestjs/common'; |
| 2 | import { PassportStrategy } from '@nestjs/passport'; |
| 3 | import { ExtractJwt, Strategy } from 'passport-jwt'; |
| 4 | |
| 5 | @Injectable() |
| 6 | export class JwtStrategy extends PassportStrategy(Strategy) { |
| 7 | constructor() { |
| 8 | super({ |
| 9 | jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), |
| 10 | ignoreExpiration: false, |
| 11 | secretOrKey: process.env.JWT_SECRET || 'secret', |
| 12 | }); |
| 13 | } |
| 14 | |
| 15 | validate(payload: { sub: string; email: string }) { |
| 16 | return { userId: payload.sub, email: payload.email }; |
| 17 | } |
| 18 | } |