ppob-backend/src/auth/jwt.strategy.ts
2021-12-14 21:48:21 +07:00

23 lines
618 B
TypeScript

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(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get<string>('secret'),
});
}
async validate(payload: any) {
return {
userId: payload.sub,
username: payload.username,
};
}
}