Last active
January 9, 2022 16:06
-
-
Save PatrickKalkman/3dc575e001061c58c73d5fe9d4573cf9 to your computer and use it in GitHub Desktop.
First layer of authentication
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
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