node.js - Sails JS - Sessions -


each time page reloaded, run 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 every time run

    console.log("session: ");     console.log(req.session); 

the player_id isn't there, , each time page reloaded, if-statement returns false.

console.log("creating player: " + req.session.player_id); 

returns correct value, can't figure out why session doesn't follow user on each page reload?

it appears solution simple this:

res.send(req.session); 

if add end of else-statement, session stored , can re-used.

why it's this, don't know. if feels elaborating, guest.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -