Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Optional flag to skip automatic session save at the end of HTTP response #992

Open
kamalyusuf opened this issue Jul 28, 2024 · 0 comments · May be fixed by #995
Open

Feature Request - Optional flag to skip automatic session save at the end of HTTP response #992

kamalyusuf opened this issue Jul 28, 2024 · 0 comments · May be fixed by #995

Comments

@kamalyusuf
Copy link

kamalyusuf commented Jul 28, 2024

When using express-session with passport.js and connect-redis store, logging in a user with req.login() triggers an immediate save of the session to the redis store. At the end of the HTTP request, .save() is called again, resulting in a redundant request to the redis server.

It would be nice if the session could take into account an optional flag, skipNextSave, which would prevent the automatic save at the end of the request cycle if it has been set. This flag should be then cleared after being checked, allowing subsequent saves to occur normally.

Proposed Implementation:

function shouldSave(req) {
  if (req.session.skipNextSave) {
    delete req.session.skipNextSave;
    return false;
  }

  // ....
}
@kamalyusuf kamalyusuf changed the title Feature Request - Optional flag to skip automatic session save Feature Request - Optional flag to skip automatic session save at the end of HTTP response Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant