Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Last active January 9, 2022 16:06
Show Gist options
  • Save PatrickKalkman/3dc575e001061c58c73d5fe9d4573cf9 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/3dc575e001061c58c73d5fe9d4573cf9 to your computer and use it in GitHub Desktop.
First layer of authentication
userController.login = function (req, reply) {
if (isValidUserRequest(req)) {
let user = db.getCleanedUser(req.body.email);
if (typeof user !== 'undefined') {
if (bcrypt.compareSync(req.body.password, user.password)) {
delete user.password;
const token = jwt.sign(user, config.jwt.secret);
const newUser = { ...user, token };
reply.code(200).send(newUser);
}
}
}
reply.unauthorized('Invalid login. Please try again.');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment