I have some basic authentication in a route that when used is throwing a console error. The following is the error:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
at ServerResponse.header
Here is the route where the error occurs. It only occurs when the "if" statement is true (the code within the if statement runs). When that doesn't run, I am not getting any error and the "home" view renders without error.
routes.get('/scan', (req, res, next) => {
const orderID = req.query.order;
const token = req.query.token;
if( !hasAccess( token ) ) {
res.status(401).send('Unauthorized');
}
res.render('home', {
order
});
}
via Jim M
No comments:
Post a Comment