1

I am using Passport js with Express js. In my application, I need a functionality that a user should be logged out from the server if he/she is idle for a certain time.

But the problem is it requires req (request) object in order to logout a user. How can I logout a user without req object.

Note: I am using cookie-session for the persistent session.

Thank you.

Arpit Kumar
  • 2,179
  • 5
  • 28
  • 53

1 Answers1

0

Old question, but in case anyone else stumbles on this as I did:

If you require logging out with req, which is only available on the server, create a route that handles the logout functionality. Then when you need to log out on the client, redirect them to the logout route. (This is often achieved with something like router.push).

Since you're using cookie-session, you can also delete the cookie instead. You will still want to redirect somewhere after, such as a "you've been logged out" page.

CaitlinWeb
  • 76
  • 3