2016-05-24 43 views
0

我正在使用connect-mongo存儲PassportJS會話。 我在server.js的conf是:ExpressJS/connect-mongo更新會話

app.use(session({ 
    name: 'Example', 
    secret:'exampleasd', 
    saveUninitialized: false, 
    resave: false, 
    cookie: { maxAge: 1000*60*60*2 }, 
    store: new MongoStore({ 
     url: 'mongodb://localhost/example', 
     host: 'localhost', 
     collection: 'user-sessions', 
     autoReconnect: true, 
     clear_interval: 3600 
    }) 
})); 

我的問題是,當我更新就像我必須退出並登錄到什麼變化的用戶名或電子郵件的用戶的數據。

我已經嘗試了req.session.save和req.session.reload,沒有運氣。

我可以在不註銷的情況下更新會話字段嗎?

謝謝!

+0

猜測'resave'應該是真實的。如果它不起作用,請將'saveUninitialized'設置爲true。 –

回答

0

你必須使用req.user正確更新req.session.passsport.user這樣:

如果要更改用戶名只是做:

req.user.username = newUsername; 
req.session.save(function(err){ 
//msg here 
});