Created
September 29, 2021 19:39
-
-
Save bttger/2aaa5c9a97006aa934a40e2be90adf0d to your computer and use it in GitHub Desktop.
find the error...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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