Created
August 21, 2022 15:43
-
-
Save ilopX/6e76398872e7b7de9c3f23d0a32e2c41 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
| async login(request: Request, response: Response) { | |
| const { email, password } = request.body; | |
| try { | |
| const user = assert(await User.findOne({ email })); | |
| assert(bcrypt.compareSync(password, user.password)); | |
| } catch(_) { | |
| return response.status(404).json({ message: 'email or password incorrect' }) | |
| } | |
| const token = jwt.sign({ | |
| email: user.email, | |
| id: user._id | |
| }, config.accessTokenSecret!, { expiresIn: '30d' }); | |
| response.status(200).json({ token }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment