From e8e380231ecc37f8b1636bacafa81be7ab24c06a Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 4 Nov 2025 23:19:53 +0700 Subject: [PATCH] fix: Login flow - remove reload, sync auth state reactively --- admin-spa/src/App.tsx | 10 +++++++++- admin-spa/src/routes/Login.tsx | 5 +---- admin/index.php | 2 +- includes/Admin/StandaloneAdmin.php | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/admin-spa/src/App.tsx b/admin-spa/src/App.tsx index 5d07041..9571c83 100644 --- a/admin-spa/src/App.tsx +++ b/admin-spa/src/App.tsx @@ -405,6 +405,13 @@ function AuthWrapper() { const location = useLocation(); useEffect(() => { + // Check if config was updated (e.g., after login) + if (window.WNW_CONFIG?.isAuthenticated !== isAuthenticated) { + setIsAuthenticated(window.WNW_CONFIG.isAuthenticated); + setIsChecking(false); + return; + } + if (window.WNW_CONFIG?.standaloneMode) { fetch(window.WNW_CONFIG.restUrl + '/auth/check', { credentials: 'include', @@ -414,12 +421,13 @@ function AuthWrapper() { setIsAuthenticated(data.authenticated); if (data.authenticated && data.user) { window.WNW_CONFIG.currentUser = data.user; + window.WNW_CONFIG.isAuthenticated = true; } }) .catch(() => setIsAuthenticated(false)) .finally(() => setIsChecking(false)); } - }, []); + }, [location.pathname, isAuthenticated]); if (isChecking) { return ( diff --git a/admin-spa/src/routes/Login.tsx b/admin-spa/src/routes/Login.tsx index 101afeb..14cd623 100644 --- a/admin-spa/src/routes/Login.tsx +++ b/admin-spa/src/routes/Login.tsx @@ -37,11 +37,8 @@ export function Login() { window.WNW_CONFIG.currentUser = data.user; window.WNW_CONFIG.nonce = data.nonce; - // Redirect to dashboard + // Redirect to dashboard (no reload needed, auth state is updated) navigate('/dashboard'); - - // Reload to ensure all auth state is fresh - window.location.reload(); } else { setError(data.message || __('Invalid username or password')); } diff --git a/admin/index.php b/admin/index.php index 8069856..389ab67 100644 --- a/admin/index.php +++ b/admin/index.php @@ -58,7 +58,7 @@ $js_url .= '?ver=' . $version; -
+