Keep user registration on restart sails.js app

I am working on a sails application which is still in development.

Every time I make a modification in the controller, I need to restart the sails with the "tug sails" command. Hopefully it can be made easier by using a forever tool that automatically detects changes and restarts.

But I need to re-login to my application (because the session is lost on restart?) Which is really not convenient.

Is there a way to preserve the user registration across restart?

+3


source to share


2 answers


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

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

      



Thus, the session data is not stored in memory and does not affect the restart of the sails.

+3


source


I haven't tested it, but you can create a policy that automatically registers the user if you are in dev mode, for example:

/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 must be called before sessionAuth if you are using this one or the one you are using to check if the user is logged in.

If you are unsure about the rules take a look here http://sailsjs.org/#!/documentation/concepts/Policies

As I know there is no official way to do this

+2


source







All Articles