We are using ASP CORE 2.x (API) with a SPA (ReactJS), I need to know what is the best strategy to track users sessions. The issue is mainly for unauthenticated users, let say we have a shopping cart. The cart is stored in the database, how do you keep the cart items of a guest user? When a guess leaves the site and comes back, we need to show the cart items.
I was planning to have a session generate by the server and saving it to the client side (in a cookie), but this means that I need to call a “ensure” session on from the client site to the server… and keeping track of the session in the db.
Any alternative or suggestions?
You can persist the shopping cart items to localStorage, and then when the user comes back just rehydrate it.
I would recommend redux-persist if you use redux.
I would associate the cart of the guest to a generated guid stored with the cart (ID?}. Passing this through cookies, the next time the guest comes, if the cookie exists and refers to a cart, I reload it. You can set some timestamp to clean pending cart on a regular base from your DB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With