jaredhanson/passport-http-bearer

Unable to run handler function in `/:id` route

Opened this issue · 1 comments

I've ran into a problem that works on a "regular" route ('/') but not on one at /:id.

passport.authenticate('bearer', { session: false }, function(err, user, info) {
if (user)
// check user's role for premium or not
if (user.role == "premium" || user.role == "editor" || user.role == "moderator" || user.role == "admin")
return ArticleModel.find(function (err, articles) {
return res.send(articles);
});
else
return ArticleModel.find(function (err, articles) {
var response = articles.filter(stripOutPremium);
return res.send(response);
});
else
// return items even if no authentication is present
return ArticleModel.find(function (err, articles) {
var response = articles.filter(stripOutPremium);
return res.send(response);
});
})(req, res, next);

Will just sit and spin forever, I get no response. I can't get the passport.authenticate('bearer'... function to run at all.

Any idea why something like this works on a simple route like app.get('/') and not app.get('/:id')?

This must have been a fluke, I'm not having a problem at all, please close...

router.get('/:id', function(req, res, next) {
passport.authenticate('bearer', { session: false }, function(err, user, info) {
if (user)
// check user's role for premium or not
if (user.role == "premium" || user.role == "editor" || user.role == "moderator" || user.role == "admin")
return ArticleModel.findById(req.params.id, function (err, article) {
return res.send(article);
});
else
return ArticleModel.findById(req.params.id, function (err, article) {
return res.send('truncated article');
});
else
// return items even if no authentication is present
return ArticleModel.findById(req.params.id, function (err, article) {
return res.send('truncated article');
});
})(req, res, next);
});