Currently, req.session.regenerate() creates a new session and destroys the previous one, including its data.
In some use cases, developers may want to change only the session ID for security reasons (such as preventing session fixation) but keep the existing session data.
I would like to propose adding an option to the regenerate() method to preserve the current session data.
req.session.regenerate({ preserveData: true });
If preserveData: true, the session data from the old session would be copied to the new session.
If omitted or false, the behavior remains unchanged.
This would allow more flexible session management without breaking existing functionality.
If the maintainers agree with this idea, I am happy to work on a PR.
Currently,
req.session.regenerate()creates a new session and destroys the previous one, including its data.In some use cases, developers may want to change only the session ID for security reasons (such as preventing session fixation) but keep the existing session data.
I would like to propose adding an option to the regenerate() method to preserve the current session data.
If preserveData: true, the session data from the old session would be copied to the new session.
If omitted or false, the behavior remains unchanged.
This would allow more flexible session management without breaking existing functionality.
If the maintainers agree with this idea, I am happy to work on a PR.