I am learning node and expressing. I am trying to create a very simple application that will simply allow the user to log in using json. Then it will conduct a session until logging out. Using asp.net, this is the doddle that you just installed in the config and call ...
Auth.Login(username,pasword)
When they log out, you simply do:
Auth.logout()
And if you need to check if they are logged in, just do:
Auth.IsLoggedIn()
Or the code for this. Passport for node seems just not that simple. I spent all night doing this work ...
app.post('/authentication/login', function handleLocalAuthentication(req, res, next) { passport.authenticate('local', function(err, user, info) { // Manually establish the session... req.login({username:' me@me.com ',password:'password'}, function(err) { if (err) return next(err); return res.json({ message: 'user authenticated' }); }); })(req, res, next); }); app.get('/authentication/isauthenticated',function(req,res){ console.log(req.isAuthenticated()); }) passport.use(new LocalStrategy( function(username, password, done) { return done(null, {username:'ss',password:'sffds'}); } ));
So now I donβt have cookies, the session is not saved when I log in, and then click URL /authentication/isAuthenticated . I can't even get a breakpoint to stay in strategy ...
passport.use(new LocalStrategy( function(username, password, done) { console.log('ggg'); return done(null, {username:'ss',password:'sffds'}); } ));
Am I looking at the wrong solution for this? Should I run my own auth or something with a basic middleware function?