Skip to content

Instantly share code, notes, and snippets.

@TheYkk

TheYkk/fast.js

Created Jan 20, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.