mongodb - How to delete express session cookie -


i using express session , mongo connect user auth, used angular client via cors request.

app.use(express.cookieparser()); app.use(express.session({     secret: 'xxxxxx',     store: new mongostore({         db: 'dbname',         clear_interval: 3600,         host: 'localhost',         port: 27017     }) })); 

the login works fine , cookie dropped , session works expected.

my problem ending session. have logout route, this:

req.session.destroy(function() {     // log out code }); 

however in mongo db.sessions, session still exists, , sid cookie still remains on user agent, if user revisits "protected" urls after logging out session regenerated.

so looks need either remove cookie or remove session db, latter seems wrong, trying remove cookie, no luck, tried in express:

req.session.destroy(function() {     res.clearcookie('connect.sid', { path: '/' }); }); 

and appears can't delete sid cookie on client javascript since http (??) didn't work:

document.cookie = 'connect.sid=; path=/; domain=localhost; expires=thu, 01 jan 1970 00:00:01 gmt;'; 

any ideas how rid of annoying session cookie??!

req.session.destroy() should clear session in db.

express using different sessionid when trying destroy session. make sure session.prototype.destroy pulling correct this.id matches id in mongodb.sessions.

i came across issue , because request server log out user wasn't containing session cookie (had left out withcredentials).

$.ajax({     url: 'http://url/auth/logout',     type: 'get',     xhrfields: {       withcredentials: true     } }); 

this caused express generate new session id request , asked mongodb remove session new id (leaving old 1 untouched).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -