feat: jwt strategy for passport

This commit is contained in:
Louis Auzuret
2022-06-20 15:48:55 +02:00
parent 70ed6328d8
commit a71b39090e
+20
View File
@@ -0,0 +1,20 @@
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
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 { id: payload.id, username: payload.username };
}
}