How to restore session on refresh?

I have users login to my webapp, if they refresh I do not want them to have to login again.
I want to connect them to the session they were on before the refresh.
I have created an array of sessions to remember the active sessions.
When the user logins in, I store the Session.Identifier as a cookie on the user’s browser as well as save the session in my active sessions.

When a refresh is done it searches for the active session, with the current users cookie value and finds it. (This all works)

My question is how do I point the session to the session of the cookie value of the user, so they don’t have to login again?


I don’t think you can. You need to save any state information you want restored in a manner that let’s a new session “resume” from that state. This includes logged in status (and account), current page, etc.

Perhaps the solutions is saving everything in cookie/s. And load it back again?

Keep in mind, Cookies can only store 2K of data.