[4.x] Fix logout on new tab #1132
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ref: GT-2426
This issue came about whenever a logged in customer opened a new tab, or even just if already logged in previously came back to the shop.
sessionStoragegets cleared, which causes the stored email to also no longer exist.There are a few alternative approaches to fixing this that I explored:
localStoragefor the user data instead. I chose not to use this solution because it didn't really address the underlying bug. Furthermore this may cause more issues with session lifetimes being exceeded.localStorageonly to store the user's email, fixing this specific check. To me, this seems like a good way to create new weird bugs with data coming from multiple different sources.At the end, I opted for the solution you see in this PR. As we really only need to call the
logged-inevent (and link a guest cart to a user) when you actually log in yourself, there is no need to also go through this every time the customer is refreshed. TheloginByTokenfunction is the only code path where you actually need to do this (thelogin-as-customercode also uses this function to log in).For safety, I changed the code so that it refreshes the cart whenever this bug would happen before.