import { Strategy } from 'passport-local' ; import { Injectable , UnauthorizedException , } from '@nestjs/common' ; import { Request } from 'express' ; import { AuthService } from '../auth.service' ; @ Injectable ( ) export class LocalRegisterStrategy extends Strategy { public name : string = 'local-register' ; constructor ( private readonly authService ) { super ( { usernameField : 'email' , passwordField : 'password' , passReqToCallback : true , } , async ( req , email , password , done ) : Promise < void > => { const { name } = req . body ; const user = await this . authService . registerUserIfNotExist ( name , email , password ) ; if ( ! user ) { return done ( new UnauthorizedException , user ) ; } return done ( null , user ) ; } ) ; } }