I have the following route upon email activation, which is only loading and not displaying when I am clicking on the url from the email. The token is there for surely so no idea what is causing it.
Any idea?
app.get('/LimeLINE/activate/:token', (req, res) => {
try {
var token = req.params.token;
} catch (e) {
log('e', 'app.get(/LimeLINE/activate/:token - e - 160 : ' + e)
return res.status(403).json({
message: "No Token"
});
}
if (token) {
//Decode the token
jwt.verify(token, "supersecret", (err, decod) => {
if (err) {
res.status(403).json({
message: "Expired Token"
});
log('err', 'app.get(/LimeLINE/activate/:token - err - 173 : ' + err)
}
req.decoded = decod;
user.activateUser(decod, (err) => {
if (err) {
return sendStatus(500)
log('err', 'app.get(/LimeLINE/activate/:token - e - 179 : ' + err)
}
//console.log(decod.username)
try {
let sTopHtml = fs.readFileSync(__dirname + '/components/top.html', 'utf8')
let sMainHtml = fs.readFileSync(__dirname + '/html/index.html', 'utf8')
let sBottomHtml = fs.readFileSync(__dirname + '/components/bottom.html', 'utf8')
// replace placeholders
sTopHtml = sTopHtml.replace('{{title}}', 'LimeLINE: Get Started')
sMainHtml = sMainHtml.replace('{{feedback-message}}', 'feedback-message')
} catch (e) {
log('e', 'app.get(/LimeLINE/activate/:token - e - 190 : ' + e)
return res.sendStatus(500)
}
return res.send(sTopHtml + sMainHtml + sBottomHtml)
})
})
}
})
One possible cause for the "hanging" request could be that the callback in the activateUser function is not being called. Make sure you always call the given callback function, i.e. on success and error.
One advice: use promises/async await as it helps you to keep your code cleaner and prevent errors like these.