Thursday, 15 January 2015

node.js - Passport.js Session Confusion -



node.js - Passport.js Session Confusion -

i learning node , express. trying build basic app allow user log in using json. maintain session until log out. asp.net doddle set in config , call...

auth.login(username,pasword)

when log out do:

auth.logout()

and if need check if logged in do:

auth.isloggedin()

or code effect. seems passport node not simple. spent night getting working...

app.post('/authentication/login', function handlelocalauthentication(req, res, next) { passport.authenticate('local', function(err, user, info) { // manually found session... req.login({username:'me@me.com',password:'password'}, function(err) { if (err) homecoming next(err); homecoming 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) { homecoming done(null, {username:'ss',password:'sffds'}); } ));

so have no cookies, no session persisted when login , nail /authentication/isauthenticated url. can't breakpoint stop in strategy...

passport.use(new localstrategy( function(username, password, done) { console.log('ggg'); homecoming done(null, {username:'ss',password:'sffds'}); } ));

am looking @ wrong solution this? should rolling own auth or basic middleware function?

check out this tutorial. it's great , helped me lot.

and here's repo has implemented passport authentication users stored in mongodb through mongoose, , hashed passwords. clone or check out, should help. https://github.com/thyforhtian/auth_base.

node.js express passport.js

No comments:

Post a Comment