File

src/module/auth/strategy/jwt.strategy.ts

Index

Methods

Constructor

constructor(authService: AuthService)
Parameters :
Name Type Optional
authService AuthService No

Methods

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

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {

	constructor(private readonly authService: AuthService) {

		super({
			jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
			secretOrKey: Config.get('JWT_SECRET')
		});

	}

	async validate(payload: any) {
		return await this.authService.authorize(payload.sub);
	}

}

result-matching ""

    No results matching ""