The trick is to not keep any session state within the stuff you redeploy. Instead:
- keep state in a separate database that persists beyond a deployment, or
- keep state purely client-side.
Where a web framework keeps state in-process or in tempfiles, a redeploy necessarily destroys that state. A subtle variant of this is if tokens or keys are generated during startup of the deployed instance, rather than being provided to the instance from some external storage.
I'd strongly recommend looking at the 12 Factor App which discusses how to create web-appish or cloudy software. It recommends that processes should be stateless and disposable, which implies that state must be external of the deployed process.