jaredhanson / passport-http-bearer

HTTP Bearer authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-http-bearer/?utm_source=github&utm_medium=referral&utm_campaign=passport-http-bearer&utm_content=about
MIT License
951 stars 142 forks source link

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

Open ghost opened 9 years ago

ghost commented 9 years ago

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')?

ghost commented 9 years ago

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); });