Skip to content

Commit

Permalink
Downgrade cart to guest cart on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
bookernath committed Dec 19, 2024
1 parent 1c9b880 commit 7ac4f6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-suits-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Downgrade customer cart to guest cart automatically on logout
8 changes: 5 additions & 3 deletions core/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const LoginMutation = graphql(`
`);

const LogoutMutation = graphql(`
mutation LogoutMutation {
logout {
mutation LogoutMutation($cartEntityId: String) {
logout(cartEntityId: $cartEntityId) {
result
}
}
Expand Down Expand Up @@ -64,12 +64,14 @@ const config = {
events: {
async signOut(message) {
const customerAccessToken = 'token' in message ? message.token?.customerAccessToken : null;
const cookieStore = await cookies();
const cartEntityId = cookieStore.get('cartId')?.value;

if (customerAccessToken) {
try {
await client.fetch({
document: LogoutMutation,
variables: {},
variables: { cartEntityId },
customerAccessToken,
fetchOptions: {
cache: 'no-store',
Expand Down

0 comments on commit 7ac4f6f

Please sign in to comment.