Session cookies do not change using ajax and nodejs server

前端 未结 1 1282
鱼传尺愫
鱼传尺愫 2021-02-10 04:39

I want to change a session cookie after an asynchronous request but no matter what I tried I keep failing. My request is as follows:

$.ajax({
    type: \"POST\"         


        
1条回答
  •  醉酒成梦
    2021-02-10 05:08

    You should call req.session.save() after the modifications if you are doing it with ajax.

    exports.setStatus = function(req, res)
    {
        req.session.userId = req.body.userId;
        req.session.token = req.body.token;
        req.session.tokenSecret = req.body.tokenSecret;
        req.session.service = req.body.service;
        req.session.loggedIn = req.body.loggedIn;
        req.session.authorized = req.body.authorized;
        req.session.save(); // This saves the modifications
    
        res.header('Access-Control-Allow-Credentials', 'true');
        res.writeHead(200);
    };
    

    0 讨论(0)
提交回复
热议问题