Thursday 15 June 2017

How to use Express and Passport Auth inside one route?

When using Express and Passport, is it possible to use the same route for both authorized users and new ones? Right now the complete route have to be protected by a Passport Strategy. Would something like this be possible? app.post('/test', function (req, res, next) { if(req.isAuthorized){ //Do something } else { //Woh! The user is not auth, do something else } } I could have a test-route that only allows authorized users, but then I would have to use a completely different route when they are not authorized, like test2... It such a small function I need and I would like to write it in the same route and controller, so the question is: Is it possible to use Express and Passport and in the same route, check if the user IS authorized? Thanks!

Submitted June 15, 2017 at 02:40PM by ProfessorRekyl

No comments:

Post a Comment