File

src/core/auth/jwt.strategy.ts

Index

Methods

Constructor

constructor(config: ConfigService, usersService: UsersService)
Parameters :
Name Type Optional
config ConfigService No
usersService UsersService No

Methods

Async validate
validate(payload: any)
Parameters :
Name Type Optional
payload any No
Returns : unknown
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';

import { UsersService } from '@app/feature/users/services/users.service';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly config: ConfigService, private readonly usersService: UsersService) {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      ignoreExpiration: false,
      secretOrKey: config.get('auth.secretKey'),
    });
  }

  async validate(payload: any) {
    await this.usersService.findOne(payload.id);
    return 'Success';
  }
}

results matching ""

    No results matching ""