diff --git a/customer-spa/src/pages/Account/components/AccountLayout.tsx b/customer-spa/src/pages/Account/components/AccountLayout.tsx
index 0ecca4b..1af594c 100644
--- a/customer-spa/src/pages/Account/components/AccountLayout.tsx
+++ b/customer-spa/src/pages/Account/components/AccountLayout.tsx
@@ -1,4 +1,4 @@
-import React, { ReactNode } from 'react';
+import React, { ReactNode, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { LayoutDashboard, ShoppingBag, Download, MapPin, Heart, User, LogOut } from 'lucide-react';
import { useModules } from '@/hooks/useModules';
@@ -12,7 +12,8 @@ export function AccountLayout({ children }: AccountLayoutProps) {
const user = (window as any).woonoowCustomer?.user;
const { isEnabled } = useModules();
const wishlistEnabled = (window as any).woonoowCustomer?.settings?.wishlist_enabled !== false;
-
+ const [isLoggingOut, setIsLoggingOut] = useState(false);
+
const allMenuItems = [
{ id: 'dashboard', label: 'Dashboard', path: '/my-account', icon: LayoutDashboard },
{ id: 'orders', label: 'Orders', path: '/my-account/orders', icon: ShoppingBag },
@@ -21,14 +22,33 @@ export function AccountLayout({ children }: AccountLayoutProps) {
{ id: 'wishlist', label: 'Wishlist', path: '/my-account/wishlist', icon: Heart },
{ id: 'account-details', label: 'Account Details', path: '/my-account/account-details', icon: User },
];
-
+
// Filter out wishlist if module disabled or settings disabled
- const menuItems = allMenuItems.filter(item =>
+ const menuItems = allMenuItems.filter(item =>
item.id !== 'wishlist' || (isEnabled('wishlist') && wishlistEnabled)
);
- const handleLogout = () => {
- window.location.href = '/wp-login.php?action=logout';
+ const handleLogout = async () => {
+ setIsLoggingOut(true);
+ try {
+ const apiRoot = (window as any).woonoowCustomer?.apiRoot || '/wp-json/woonoow/v1';
+ const nonce = (window as any).woonoowCustomer?.nonce || '';
+
+ await fetch(`${apiRoot}/auth/logout`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-WP-Nonce': nonce,
+ },
+ credentials: 'include',
+ });
+
+ // Full page reload to clear cookies and refresh state
+ window.location.href = window.location.origin + '/store/';
+ } catch (error) {
+ // Even on error, try to redirect and let server handle session
+ window.location.href = window.location.origin + '/store/';
+ }
};
const isActive = (path: string) => {
@@ -52,7 +72,7 @@ export function AccountLayout({ children }: AccountLayoutProps) {
-
+
@@ -93,11 +117,10 @@ export function AccountLayout({ children }: AccountLayoutProps) {