Reputation:
i making single page web with login with Reactjs. Problem is how and where to save token expire time. Do i need to save in sessionStore, but when browser closes all data will be deleted. Local Store? But then data will be forever. Or i can save in localStore and in every event i have to add function, that checks expire time from localStore, when event triggered successfully update localstore again? but code will look horrible... and how about performance issues? Is this approuche acceptible?
Upvotes: 1
Views: 7824
Reputation: 18664
Do you use Redux && Redux thunk?
If so, here's the approach I followed:
More details, for the above flow, you can check in the original answer (where from I took inspirations): https://stackoverflow.com/a/36986329/4312466
If you don't use any State management libraries:
It's an option to follow the above idea, but instead of having a store, middleware, and using redux-persist, you can:
localStore
.However, if you do SPA and have complex state operations, I recommend you to use some State management library.
Upvotes: 2