-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When auth token is invalid reset cart and refetch details #2379
Conversation
37b26df
to
8455fda
Compare
|
Signed-off-by: sirugh <rugh@adobe.com>
err => | ||
err.message.includes('Could not find a cart') || | ||
err.message.includes( | ||
'The current user cannot perform operations on cart' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addition is all that is necessary for the user flow to "work". The other changes in this PR are to make the UI (cart trigger item qty) update properly without having to refresh the page or add another item
const [, { toggleDrawer }] = useAppContext(); | ||
const [{ cartId }, { getCartDetails }] = useCartContext(); | ||
|
||
const [getItemCount, { data }] = useLazyQuery(getItemCountQuery); | ||
const [getItemCount, { data }] = useLazyQuery(getItemCountQuery, { | ||
fetchPolicy: 'cache-and-network' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sirugh - I couldn't get the CartTrigger to update without a refreshing unless I added this fetch policy. I suspect because the manual cache deletions don't trigger lifecycle events, it was still pulling the value from the in-memory cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good.
Running through the verification steps though,
- Log in and add an item to your cart.
- In local storage, change the M2_VENIA_BROWSER_PERSISTENCE__signin_token entry to have a > timeStored of some low number like 1.
- Add another item to your cart. The operation should succeed but the cart should only have the > item you just added. The cart trigger should be updated to show 1 item in the cart.
Then I sign out and sign back in again. The item I added in step 1 is in my cart, not the item I added in step 3. This doesn't seem correct.
Edit: Well, I guess that does make sense.
But it's confusing to a user (in this case me) that my authed cart got swapped out for a guest cart. When I add that second item I have no idea that my auth expired. Everywhere else in the app (left drawer) says I'm signed in (authed).
await dispatch(signOut()); | ||
} else { | ||
// Delete the cached ID from local storage. | ||
await dispatch(removeCart()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little surprised to see this as an else
. I'm assuming both removeCart
and signOut
delete the auth token from local storage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok nevermind, just read user/asyncActions
. Might be useful to add that removeCart
is called as part of signOut
to the comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to investigate this more; this change should be resetting customer global state back to initial guest values, so if there are still components rendering like you're logged in, there's a bug somewhere.
Will add that comment and resolve the one area I've observed stale data (left drawer is still pinned like you're logged in). Did you see any other components still rendering with customer data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the one I noticed too. No others I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ae8fe42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verification steps
@@ -62,9 +71,10 @@ export const useAuthModal = props => { | |||
}, [showMyAccount]); | |||
|
|||
const handleSignOut = useCallback(async () => { | |||
setIsSigningOut(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this ever go back to false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do we rely on unmount for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this callback will trigger a page refresh, performing the reset for us.
After adding the second item in the verification steps I'm still appearing as signed in when I open the left drawer. So I think I'm signed in with item (2) as the only thing in my cart. |
@supernova-at - I didn't even run through those verification steps 🤦 this has been resolved in e41d29f. |
This is much better - thanks! I still think there's some awkwardness here, but that may just be the nature of the issue. Off the top of my head I was thinking a toast or something to inform the user that they've been signed out, or better yet a prompt asking if they'd like to "stay signed in". Since we don't have UX for any of that though, I think there's enough value here to get this in. |
Performance Test Results The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate. https://pr-2379.pwa-venia.com : LH Performance Expected 0.85 Actual 0.57, LH Best Practices Expected 1 Actual 0.92 |
Description
The retry logic was not functioning when a guest user tried to perform an operation on an "authed" cart. This situation could arise if a user signs in and then the auth token expires naturally (1 hour ttl). The old, authed, cart id persisted and was used but since there was no more token in store the request failed.
Related Issue
Closes #2378 .
Acceptance
Verification Stakeholders
Specification
Verification Steps
M2_VENIA_BROWSER_PERSISTENCE__signin_token
entry to have atimeStored
of some low number like1
.1
item in the cart.Rerun the above steps but on step 3 refresh the page and then add an item.
Screenshots / Screen Captures (if appropriate)
Checklist