Passport authentication not working in sails.js application
authentication, node.js, passport-local, passport.js, sails.js
Solution
Passport doesn't have a policy to deny access to a controller. For this, you have to create another policy.
See this link for more details.
Problem
I have a Sails JS application. I am trying to setup authentication using Passport.js authentication layer sails-generate-auth. I have configured my app by following the steps given in their documentation. But when I lift my sails app, authentication is not working. I am able to access the controllers, even when I am not logged in (It's not redirecting to my login page). I added a `console.log` statement in `api/policies/passport.js` as follows: ``` module.exports = function (req, res, next) { passport.initialize()(req, res, function () { passport.session()(req, res, function () { res.locals.user = req.user; console.log(req.user); // added by me next(); }); }); }; ``` Now, when I access controllers before login or after logout, its printing `undefined`. But when I am logged in, its printing my user data. Any idea why it is not checking for authentication? I am using local authentication strategy and I have commented out all others (twitter, facebook...)