INNER CODE UNIT · JavaScript
function
adnanrahic/securing-restful-apis-with-jwt · auth/AuthController.js:53
function (err, user) {
if (err) return res.status(500).send("There was a problem registering the user`.");
// if user is registered without errors
// create a token
var token = jwt.sign({ id: user._id }, config.secret, {
expiresIn: 86400 // expires in 24 hours
});
res.status(200).send({ auth: true, token: token });
});
});
router.get('/me', VerifyToken, function(req, res, next) {
User.findById(req.userId, { password: 0 }, function (err, user) {
if (err) return res.status(500).send("There was a problem finding the user.");