Cookie值不会改变表达nodejs

时间:2017-12-18 14:09:26

标签: node.js express cookies socket.io

我正在使用Express Framework和socket.io。我正在处理身份验证部分,我无法更改cookie的值。请参阅代码。

var session = require('express-session');

app.use(cookieParser());

app.use(session({
    secret: "kvkjsdsbj12334",
    resave:false,
    saveUninitialized: false,
    cookie:{
        authStatus: "NotLoggedIn",
        secure: false
    },
    rolling: true
}));

app.use(function (req, res, next){
    console.log(req.session.cookie.authStatus); // Logs NotLoggedIn after /login.
});

app.post('/login',(req,res)=>{
       var body = _.pick(req.body,['email','password']);   
       var email = body.email;
       var password = body.password;

                  
       Users.findByCredentials(body.email,body.password).then((user)=>{
             req.session.user = user;
             req.session.cookie.authStatus = "loggedIn";
             req.session.save();
             //Redirected from here   
       });   

});

0 个答案:

没有答案