Created
January 20, 2020 10:50
-
-
Save TheYkk/5531428795f6c2f68ebd432367380dd5 to your computer and use it in GitHub Desktop.
Bug js
This file contains 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
// ? 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