0

How to set session value in callback? Why it doesn't work?

app.get('/room/:id', function(req, res) {
    var room_id = req.param('id');
    room.getRoom(room_id, function(err, result) {
        if(result.length) {
            req.session.code_room = room_id;
        }
    }); 
    res.render('room.jade');
});

1 Answer 1

1

You probably should move res.render to the inside of callback function:

app.get('/room/:id', function(req, res) {
    var room_id = req.param('id');
    room.getRoom(room_id, function(err, result) {
        if(result.length && !err) {
            req.session.code_room = room_id;
        } else {
            //sorry...
            req.session.code_room = -1;
        }
        res.render('room.jade');
    }); 
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.