reactioncommerce / reaction

Mailchimp Open Commerce is an API-first, headless commerce platform built using Node.js, React, GraphQL. Deployed via Docker and Kubernetes.
https://mailchimp.com/developer/open-commerce/
GNU General Public License v3.0
12.35k stars 2.17k forks source link

Refactor session logic to anonymous user accounts #393

Closed aaronjudd closed 9 years ago

aaronjudd commented 9 years ago

Current Session behaviour:

new session
return all orders for sessionId  (0)
places an order as a guest - we now have 1 session order
login as user - place order - we now have 2 session order returned (same session)
logout as user - we now have 1 session order returned
clear session - > we now have 0 orders
login as user -> we now have 1 user order
logout as user -> we now have 0 orders
place order as guest -> we now have 1 guest (session) order

the problem is.. what should the logic be when the same session exists. Creating a new session after an order is placed should resolve this (but may have some complications)

aaronjudd commented 9 years ago

@mikemurray I'm looking into using anonymous user accounts, rather than maintaining the "sessions" logic. I don't remember my logic for not doing this from the get go, but I assume I felt it would be both a maintenance and performance issue. (ie: creating a lot churn on the users collection). The upside is that we'd only every have to deal with the users collection, and can refactor easily broken and complex bits that've been bothersome for a while - (caused mainly I think in an attempt to avoid this approach). This will complete remove sessions from cart handling.

This means every user would start as logged in to a unique anonymous account, unless they have already logged in as regular user. This would change the accounts UI flow in #348 reaction-accounts.

Here's how I'm thinking the accounts workflow could work.

UIX

Merge

@queso appreciate your thoughts on this as well...

boboci9 commented 9 years ago

I think this is linked to this issue but when you log in the system with a user and then create an order then log out the completed page is still there with multiple orders, some of which weren't made with the user who was last logged in (but they shouldn't be shown if noone is logged in) The list of the orders on the completed page are selected by sessionId I think, and not by user because the list contains orders which were not made by the current user.

newsiberian commented 8 years ago

Hi. As far as I understand, current logic of sessions flow may be illustrated by this diagram: schema

So, as you could see, we got a problem here. I've just started to think how to fix that... Maybe someone has ideas on this case?

newsiberian commented 8 years ago

Hello, here what we have: sessionid2 We can try to cut out all ReactionCore.sessionId global use cases, by passing real sessionId to this methods. And maybe remove the session collection completely as next step. As you can see, there is a one place - ReactionCore.MethodHooks.after("cart/submitPayment") - where we can't pass browser's sessionId directly. But we can do it from cart/submitPayment, so maybe we don't need this hook at all? Could we, for example, add this functionality to some new method, witch will be called after cart/submitPayment? Or maybe we could add this snippet to the end of cart/submitPayment? @aaronjudd, I will be waiting for your decision here.

UPD (02.01): problem with hook solved.