Skip to content

Instantly share code, notes, and snippets.

@ilopX
Created August 21, 2022 15:43
Show Gist options
  • Select an option

  • Save ilopX/6e76398872e7b7de9c3f23d0a32e2c41 to your computer and use it in GitHub Desktop.

Select an option

Save ilopX/6e76398872e7b7de9c3f23d0a32e2c41 to your computer and use it in GitHub Desktop.
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