4
votes

I'm working on a sails app still under development.

Each time I make a modification in a controller, I need to restart sails with a 'sails lift' command. Hopefully, it can be eased by using 'forever' tool which detect modifications and restart automatically.

But I need to re-log into my application (because the session is lost when restarting ?) which is really not convenient.

Is there any way to keep the user logged when restarting ?

2

2 Answers

5
votes

You can install redis locally and use it as a session store for development by installing connect-redis and adding the following lines to config/env/development.js

module.exports = {
  session : {
    adapter: 'redis'
  }
}

This way session data is not stored in memory and are not affected from sails restarts

2
votes

I didn't test it but you can create a policy that automatically log your user if you are in dev mode like this :

/api/policies/autolog.js

module.exports = function (req, res, next)
{
  //If not logged and sails launch is dev mode, we automatically log user
  if (!req.session.authenticated && sails.config.environment == "development")
  {
    //Do whatever you want to log my user and put it in session 
    req.session.authenticated = true;
  }

  return next();
};

This policy have to be call before sessionAuth if you use this one or the one you use to test if user is logged.

If you don't know about policies just look here http://sailsjs.org/#!/documentation/concepts/Policies

As I know there no official way to do it