Files
Reactive-Resume/apps/server/src/auth/strategy/local.strategy.ts
Amruth Pillai 8b217dfcfa - upgrade react-resizable-panels to latest version
- update translations
- remove cypress
- add await to all return blocks
2023-11-19 09:52:55 +01:00

22 lines
746 B
TypeScript

import { BadRequestException, Injectable } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
import { ErrorMessage } from "@reactive-resume/utils";
import { IStrategyOptions, Strategy } from "passport-local";
import { AuthService } from "../auth.service";
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy, "local") {
constructor(private readonly authService: AuthService) {
super({ usernameField: "identifier" } as IStrategyOptions);
}
async validate(identifier: string, password: string) {
try {
return await this.authService.authenticate({ identifier, password });
} catch (error) {
throw new BadRequestException(ErrorMessage.InvalidCredentials);
}
}
}