Skip to content

Commit e941c0d

Browse files
committed
fix: m2-1017 logout doesn't work after reload of the MyAccount page
1 parent a3e5241 commit e941c0d

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

packages/theme/modules/customer/pages/MyAccount/MyAccount.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
:label="$t(item.label)"
3535
:link="localeRoute(item.link)"
3636
class="sf-content-pages__menu"
37-
v-on="item.listeners"
37+
v-on="{ click: getHandler(item.id) }"
3838
/>
3939
</li>
4040
</SfList>
@@ -83,17 +83,28 @@ export default defineComponent({
8383
}
8484
});
8585
86-
const { sidebarLinkGroups } = useSidebarLinkGroups();
86+
const { sidebarLinkGroups, logoutUser } = useSidebarLinkGroups();
8787
8888
const isOnSubpage = computed(() => route.value.matched.length > 1);
8989
const goToTopLevelRoute = () => router.push(localeRoute({ name: 'customer' }));
9090
const title = computed(() => i18n.t(route.value.matched.at(-1)?.meta.titleLabel as string));
9191
92+
/**
93+
* #tab-id: handler-name
94+
*/
95+
const handlers = {
96+
'log-out': logoutUser,
97+
};
98+
99+
const getHandler = (id: string) => handlers[id] ?? {};
100+
92101
return {
93102
sidebarLinkGroups,
94103
title,
95104
isOnSubpage,
96105
goToTopLevelRoute,
106+
logoutUser,
107+
getHandler,
97108
};
98109
},
99110
});
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
import type { RawLocation } from 'vue-router';
2+
23
import { useRouter, useContext } from '@nuxtjs/composition-api';
34
import { useUser } from '~/modules/customer/composables/useUser';
45
import { useCart } from '~/modules/checkout/composables/useCart';
56

67
type LinkGroup = { title: string, items: LinkGroupItem[] };
7-
type LinkGroupItem = { label: string, link?: RawLocation, listeners?: Record<string, () => (Promise<void> | void)> };
8+
type LinkGroupItem = { id: string, label: string, link?: RawLocation };
89

910
export const useSidebarLinkGroups = () => {
1011
const { localeRoute } = useContext();
1112
const { logout } = useUser();
1213
const { clear } = useCart();
13-
1414
const router = useRouter();
15+
1516
const sidebarLinkGroups : LinkGroup[] = [
1617
{
1718
title: 'Personal details',
1819
items: [
1920
{
21+
id: 'my-profile',
2022
label: 'My profile',
2123
link: { name: 'customer-my-profile' },
2224
},
2325
{
26+
id: 'address-details',
2427
label: 'Addresses details',
2528
link: { name: 'customer-addresses-details' },
2629
},
2730
{
31+
id: 'my-newsletter',
2832
label: 'My newsletter',
2933
link: { name: 'customer-my-newsletter' },
3034
},
3135
{
36+
id: 'my-wishlist',
3237
label: 'My wishlist',
3338
link: { name: 'customer-my-wishlist' },
3439
},
@@ -38,26 +43,28 @@ export const useSidebarLinkGroups = () => {
3843
title: 'Order details',
3944
items: [
4045
{
46+
id: 'order-history',
4147
label: 'Order history',
4248
link: { name: 'customer-order-history' },
4349
},
4450
{
51+
id: 'my-reviews',
4552
label: 'My reviews',
4653
link: { name: 'customer-my-reviews' },
4754
},
4855
{
56+
id: 'log-out',
4957
label: 'Log out',
50-
listeners: {
51-
click: async () => {
52-
await logout({});
53-
await clear({});
54-
await router.push(localeRoute({ name: 'home' }));
55-
},
56-
},
5758
},
5859
],
5960
},
6061
];
6162

62-
return { sidebarLinkGroups };
63+
const logoutUser = async () => {
64+
await logout({});
65+
await clear({});
66+
await router.push(localeRoute({ name: 'home' }));
67+
};
68+
69+
return { sidebarLinkGroups, logoutUser };
6370
};

0 commit comments

Comments
 (0)