21 lines
650 B
TypeScript
21 lines
650 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
import { UserService } from './user.service';
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(private configService: ConfigService) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: configService.get('JWT_SECRET')!,
|
|
});
|
|
}
|
|
|
|
async validate(payload: any) {
|
|
return { userId: payload.id, username: payload.usuario };
|
|
}
|
|
}
|