Created
July 29, 2019 20:20
-
-
Save chewtoys/edc426f22404fc78337941cc0252ec80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Find user by email | |
| */ | |
| async findUser(options) { | |
| const { | |
| email, | |
| password, | |
| } = options | |
| if (!email) { | |
| throw new Error({ | |
| message: 'An email is required', | |
| }) | |
| } | |
| const user = await this.findOne({ | |
| email, | |
| }).exec() | |
| const err = { | |
| status: httpStatus.UNAUTHORIZED, | |
| isPublic: true, | |
| } | |
| if (password) { | |
| if (user && await user.passwordMatches(password)) { | |
| return { | |
| user | |
| } | |
| } | |
| err.message = 'Incorrect email or password' | |
| } else { | |
| err.message = 'Incorrect email' | |
| } | |
| throw new Error(err) | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment