Complete the code to import the Passport local strategy in NestJS.
import { [1] } from '@nestjs/passport';
The PassportStrategy is imported from @nestjs/passport to implement username/password authentication.
Complete the constructor to inject the AuthService in the LocalStrategy class.
constructor(private readonly [1]: AuthService) {}The authService is injected to validate user credentials in the local strategy.
Fix the error in the validate method signature to properly receive username and password.
async validate([1]: string, password: string): Promise<any> {The validate method receives username and password as parameters to check credentials.
Fill both blanks to correctly call the AuthService validateUser method and handle invalid user.
const user = await this.authService.[1]([2], password); if (!user) { throw new UnauthorizedException(); }
The validateUser method is called with username and password to verify credentials.
Fill all three blanks to complete the LocalStrategy class extending PassportStrategy and calling super with the correct options.
export class LocalStrategy extends PassportStrategy([1]) { constructor(private readonly authService: AuthService) { super({ usernameField: [2] }); } async validate(username: string, [3]: string): Promise<any> { const user = await this.authService.validateUser(username, password); if (!user) { throw new UnauthorizedException(); } return user; } }
The class extends PassportStrategy(Strategy). The super call sets usernameField to 'username'. The validate method receives username and password.