0

I am working on a mean.js application, and using the following code for session timeout:

app.use(session({
    saveUninitialized: true,
    resave: true,
    secret: config.sessionSecret,
    store: new mongoStore({
        db: db.connection.db,
        collection: config.sessionCollection
    }),
    cookie: { maxAge : 1800000 },
    rolling: true
}));

It is working perfect. The issue is that when the session expires the page remains in the same state and if the user clicks on any of the links it redirects to the login page.

I need to implement that instead of user click if the session is expired the page should auto redirect to the login page.

Thanks in advance.

Priyank
  • 1
  • 1
  • 5

2 Answers2

0

mean.js use angular on the client, so your question is the same like

How to redirect to login page after cookie expires in Angular JS?

Community
  • 1
  • 1
Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46
  • Thanks Andriy is there any way on configuration level to achieve it? – Priyank Sep 11 '15 at 08:01
  • and in the example provided the page will not redirect automatically to login page. This is already implemented that after the time specified in maxAge if user clicks on any other link the application redirects to login page, but the requirement is to redirect the page to login page automatically if the session is expired. – Priyank Sep 11 '15 at 09:58
  • It will. The only one way to do it "automatically" is to set timeout in client js to verify every XX second if cookie is expired. So in the answers to that link you could see $timeout(function(){if(!$cookieStore.get('user')){$window.location.href = 'redirectlink';}},60); – Andriy Kuba Sep 11 '15 at 15:01
0

Finally i got exactly what was required here:

http://hackedbychinese.github.io/ng-idle/

Priyank
  • 1
  • 1
  • 5