I'm trying to use jwt in nest Everything is ok, but validate function is not working in jwt.strategy.ts
this is my jwt.strategy.ts:
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private userService:UserService
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey:"mysecretkey",
});
}
async validate(payload:any) {
console.log('this is payload'+payload)
it prints: this is payload undefine
user.modul
@Module({
exports:[UserService],
controllers: [UserController],
providers: [UserService,JwtStrategy],
imports : [TypeOrmModule.forFeature([UserEntity]),PassportModule.register(
{defaultStrategy:'jwt'}),
JwtModule.register({secret:'mysecretkey',signOptions:{expiresIn:3600000}})]
})
export class UserModule {}
When i request in postman, i get satus:401 Unauthorized and in termenal show : payload undefined