Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Nov 13, 2014 · 1 comment
Open

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

ghost opened this issue Nov 13, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 13, 2014

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
Copy link
Author

ghost commented Nov 13, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants