Skip to content

Instantly share code, notes, and snippets.

@TheYkk
Created January 20, 2020 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheYkk/5531428795f6c2f68ebd432367380dd5 to your computer and use it in GitHub Desktop.
Save TheYkk/5531428795f6c2f68ebd432367380dd5 to your computer and use it in GitHub Desktop.
Bug js
// ? Login user
fastify.post(
'/login',
{
schema: {body: loginSchema},
},
async (req, res) => {
const {email, password} = req.body;
await UserModel.getAuthenticated(email, password, (err, user) => {
if (err) {
req.log.warn(`User login error:`, err);
res.send({
error: true,
desc: 'User login failed',
});
}
if (user) {
// ? Login ok send user
const token = fastify.jwt.sign({id: user});
res.send({
error: false,
desc: 'Login succesfuly',
user,
token,
});
} else {
req.log.warn(`User not found`, err);
res.send({
error: true,
desc: 'Email or password incorrect',
});
}
});
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment