Cheese Puffs
Cheese Puffs

Reputation: 985

SailsJS - Session maxAge/expires

I'm having some issues with my session, which expires when I close my browser. I don't want that.

I've tried to set both maxAge and/or a expire date, but everytime I restart my browser, that session is gone. From my understanding, it isn't supposed to expire when I close my browser if i have a maxAge, am I wrong here?

Here is a piece of my login function where I set my session if successful.

Login:

login: function(req, res) {
    // A bunch of checks
    ..
    if(success) {
        //req.session.cookie.expires = newDate;
        req.session.cookie.maxAge = 60 * 60 * 1000;
        req.session.authenticated = true;
        res.json(req.session);
    }
}

Everytime i open up my application, I run this function below, to see if a session is active. It works great if i refresh the page, or even close the tab. Then the session remains and I am still logged in. However, when I close it, it's gone like the wind :)

sessionCheck:

sessionCheck: function(req, res, next) {
    console.log(req.session); // Has expired on browser close.

    if(req.session.authenticated) {
        res.json(req.session);
    } else {
        ..
    }
}

Any ideas where my mistakes lies? Or have i misunderstood how session works here? If so, any pointers is appreciated.

Goal:: Want to keep session when browser is restarted.

Upvotes: 0

Views: 730

Answers (1)

zieglar
zieglar

Reputation: 830

you can keep session use redis/mongo/cookie, look at config/session.js, you should overwrite it at config/local.js.

Upvotes: 1

Related Questions