在firefox上重定向后req.session没有刷新

时间:2014-05-22 19:55:15

标签: node.js session express

我想在路线中设置req.session并将其用于另一个路线。但事实是,它只是在firefox上才能刷新(它在Chrome& Co中运行良好)。我在客户端中设置对象:

<object type="text/html" id="chat-object" data="http://localhost:8080/login/?username=<?php echo $nom_joueur?>&room=<?php echo $id_partie ?>&id=<?php echo $id_joueur; ?>"></object>

php变量很好。

我做了这样的服务器部分:

app.get('/', [requireLogin], function (req, res, next) {
    res.render('index', {
        "username": req.session.username
    });
    console.log("req = ", JSON.stringify(req.session));
});

/** Login form */
app.get("/login", function (req, res) {
    var options = {
        "username": req.query.username,
        "room_id": req.query.room,
        "error": null
    };
    console.log("reqSession=" + JSON.stringify(req.session));
    console.log("app.get login, option = " + JSON.stringify(options));
    if (!req.query.username && !req.query.room && !req.session.username && !req.session.room) {
        options.error = "User name and room id are required";
        res.render("login", options);
    } else if (req.query.username == req.session.username && req.query.room == req.session.room) {
        // User has not changed username or room, accept it as-is
        res.redirect("/");
    } else {
        req.session.username = req.query.username;
        req.session.room = req.query.room;
        req.session.id_user = req.query.id;
        res.redirect("/");
    }
    console.log("app.get login, session = " + JSON.stringify(req.session));
});

/ login的日志告诉我:

app.get login, session = {"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"username":"Testeur 1","id_user":"2","room":"5"}

和/的日志给了我:

req =  {"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"username":"Testeur 1","id_user":"2"}

我真的不明白之间发生了什么。

0 个答案:

没有答案