Skip to content

Instantly share code, notes, and snippets.

@bttger
Created September 29, 2021 19:39
Show Gist options
  • Save bttger/2aaa5c9a97006aa934a40e2be90adf0d to your computer and use it in GitHub Desktop.
Save bttger/2aaa5c9a97006aa934a40e2be90adf0d to your computer and use it in GitHub Desktop.
find the error...
/**
* Checks if the provided credentials are correct and returns corresponding
* employer entity
*
* @throws 404 NotFound Exception (email not found)
* @throws 401 Unauthorized Exception (email and password combination wrong)
* @param email
* @param password
*/
async validateCredentialsEmployer(
email: string,
password: string,
): Promise<Employer> {
let employer: Employer;
try {
employer = await this.employerRepository.findOneOrFail({ email: email });
} catch (error) {
throw new NotFoundException();
}
const valid = bcrypt.compare(password, employer.passwordHash);
if (!valid) {
throw new UnauthorizedException();
}
return employer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment