Every time the page reloads, I run this function:
init: function(req, res) { console.log("Session: "); console.log(req.session); if (req.session.player_id !== undefined) { Player.getPlayer(req.session.player_id); } else { req.session.player_id = sails.uuid.v4(); req.session.save(); console.log("Session saved"); Player.createPlayer(req.session.player_id); console.log("Creating player: " + req.session.player_id); } }
The problem is that every time I run
console.log("Session: "); console.log(req.session);
Player_id does not exist, and every time the page reloads, the if statement returns false.
console.log("Creating player: " + req.session.player_id);
It returns the correct value, but I cannot understand why the session does not follow the user every time the page is reloaded?
source share