forked from Yara724/api
24 lines
732 B
TypeScript
24 lines
732 B
TypeScript
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<any> {
|
|
const user = await this.userAuthService.validateUser(username, password);
|
|
if (!user) {
|
|
throwUserAuthError(UserAuthErrorCode.OTP_INVALID);
|
|
}
|
|
return user;
|
|
}
|
|
}
|