diff --git a/admin-spa/src/App.tsx b/admin-spa/src/App.tsx index 26fcf5c..58dffc4 100644 --- a/admin-spa/src/App.tsx +++ b/admin-spa/src/App.tsx @@ -266,7 +266,7 @@ function Header({ onFullscreen, fullscreen, showToggle = true }: { onFullscreen: const handleLogout = async () => { try { - await fetch(window.WNW_CONFIG.restUrl + '/auth/logout', { + await fetch((window.WNW_CONFIG?.restUrl || '') + '/auth/logout', { method: 'POST', credentials: 'include', }); @@ -465,7 +465,7 @@ function AuthWrapper() { // In standalone mode, trust the initial PHP auth check // PHP uses wp_signon which sets proper WordPress cookies if (window.WNW_CONFIG?.standaloneMode) { - setIsAuthenticated(window.WNW_CONFIG.isAuthenticated); + setIsAuthenticated(window.WNW_CONFIG.isAuthenticated ?? false); setIsChecking(false); } else { // In wp-admin mode, always authenticated diff --git a/admin-spa/src/routes/Login.tsx b/admin-spa/src/routes/Login.tsx index 6810a9b..60b46cf 100644 --- a/admin-spa/src/routes/Login.tsx +++ b/admin-spa/src/routes/Login.tsx @@ -20,7 +20,7 @@ export function Login() { setError(''); try { - const response = await fetch(window.WNW_CONFIG.restUrl + '/auth/login', { + const response = await fetch((window.WNW_CONFIG?.restUrl || '') + '/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -118,7 +118,7 @@ export function Login() { {/* Footer Links */}
diff --git a/admin-spa/src/types/window.d.ts b/admin-spa/src/types/window.d.ts index 91ea126..2bc5e81 100644 --- a/admin-spa/src/types/window.d.ts +++ b/admin-spa/src/types/window.d.ts @@ -16,11 +16,39 @@ interface WNW_WC_MENUS { items?: any[]; } +interface WNW_CONFIG { + standaloneMode?: boolean; + restUrl?: string; + wpAdminUrl?: string; + siteUrl?: string; + siteName?: string; + isAuthenticated?: boolean; + currentUser?: { + id: number; + name: string; + email: string; + }; + user?: { + id: number; + name: string; + email: string; + }; + store?: { + currency: string; + currencySymbol: string; + currencyPosition: string; + thousandSeparator: string; + decimalSeparator: string; + decimals: number; + }; +} + declare global { interface Window { WNW_API?: WNW_API_Config; wnw?: WNW_Config; WNW_WC_MENUS?: WNW_WC_MENUS; + WNW_CONFIG?: WNW_CONFIG; } }