UNPKG

ticket-auth-project

Version:

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

23 lines (21 loc) 708 B
import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { Strategy, ExtractJwt } from 'passport-jwt'; import { UsersService } from 'src/users/users.service'; @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor(private usersService: UsersService) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), ignoreExpiration: false, secretOrKey: 'secretMerhad', }); } async validate(payload: any) { const user = await this.usersService.findByUsername(payload.username); if (!user) { throw new UnauthorizedException(); } return user; } }