I have been trying to implement rememberme functionality using sails. I want a session to persist until the browser is closed. However, if a rememberme checkbox is ticked when the user logins in I want the session to persist for 30 days. I used the remember me passport strategy from here: https://github.com/jaredhanson/passport-remember-me but it ends up sitting on top of the sails session and the one called first ends up superseding the other.
You can set the cookie age just before calling the login function.
I did it in my login controller -> passport.callback.
passport.callback(req, res, function (err, user, challenges, statuses) {
...
if (req.param('remember', false) == true) {
req.session.cookie.maxAge = 1000 * 60 * 60 * 24 * 30;
}
req.login(user, function (err) {
...
}
}
This doesn't really feel right and, if you are sending some other cookies when logging in, it will affect their lifetime as well.
But it works and I went with it since finding documentation for sails-related stuff is like digging oil.
Also, I noticed that Passport was not destroying sessions properly upon and had to do it manually by calling req.session.destroy(); in the logout controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With