import { Strategy } from 'passport-local' ; import { PassportStrategy } from '@nestjs/passport' ; import { Injectable , UnauthorizedException } from '@nestjs/common' ; import { decryptValue } from '@utils/crypto' ; import { AuthService } from '../auth.service' ; @ Injectable ( ) export class LocalStrategy extends PassportStrategy ( Strategy ) { constructor ( private authService ) { super ( { usernameField : 'userId' , passwordField : 'password' , } ) ; } async validate ( userId , password ) { const user = this . authService . validateUser ( decryptValue ( userId ) , decryptValue ( password ) ) ; if ( ! user ) throw new UnauthorizedException ( ) ; return user ; } }