ctrlplusb / react-universally

A starter kit for universal react applications.
MIT License
1.7k stars 244 forks source link

Best approach for storing data in session? #498

Closed saniko closed 6 years ago

saniko commented 6 years ago

Hi, What is the best approach to store data in session? I'm using mobx as a store, and would like to be able to set and retrieve data between browser refreshes. Obviously, I cannot use sessionStorage.

What are guys doing? using 'config' for this or some CLIENT variable?

Thanks.

williamoliveira commented 6 years ago

Right now the only thing I am storing is the auth access token, I stored it in a cookie as I need it in the server too

So my flow is: user log in -> save access token to cookie -> user refresh page -> browser sends the cookie to server -> on the server I get the access token from cookie -> fetch data from my api using the token -> render everything -> dump all the state to html -> send html+state to client -> react is happy with no html mismatch

nialloc9 commented 6 years ago

I used redux but I used express session and when the user logged in I store the data in a session Then I checked if the session data was available before creating the store. If it was use that otherwise use some default state.