import { Injectable , UnauthorizedException } from '@nestjs/common' ; import { PassportStrategy } from '@nestjs/passport' ; import { Strategy } from 'passport-local' ; import type { Payload } from '../auth.interface' ; import { AuthService } from '../auth.service' ; @ Injectable ( ) export class LocalStrategy extends PassportStrategy ( Strategy ) { constructor ( private auth ) { super ( ) ; } public async validate ( username , password ) { const user = await this . auth . validateUser ( username , password ) ; if ( ! user ) { throw new UnauthorizedException ( 'NotFoundUser' ) ; } return { userId : user . id , username : user . name , roles : user . roles } ; } }