express.cookieSession break session.destroy

时间:2013-10-16 01:53:31

标签: session cookies express

这是我的Express应用程序配置的样子:

app.use(express.bodyParser());

app.use(express.cookieParser());
app.use(express.cookieSession({secret: conf.sessionSecret}));
app.use(express.session({secret: conf.sessionSecret}));

app.use(app.router);

每当我这样做时:

app.get('/logout', function (req, res)
    {
        res.clearCookie('userId');
        req.session.destroy();
        res.redirect('/login');
    });

我明白了:

TypeError: Object #<Object> has no method 'destroy'.

取出app.use(express.cookieSession());解决它。这是为什么?

1 个答案:

答案 0 :(得分:2)

对于express.cookieSession,请设置:

req.session = null;