import { Injectable } from "@nestjs/common"; import { PassportStrategy } from "@nestjs/passport"; import { Strategy } from "passport-local"; import { UserAuthErrorCode, throwUserAuthError, } from "src/auth/auth-services/user-auth-error"; import { UserAuthService } from "src/auth/auth-services/user.auth.service"; @Injectable() export class LocalStrategy extends PassportStrategy(Strategy) { constructor(private readonly userAuthService: UserAuthService) { super(); } async validate(username: string, password: string): Promise { const user = await this.userAuthService.validateUser(username, password); if (!user) { throwUserAuthError(UserAuthErrorCode.OTP_INVALID); } return user; } }