fix: Login flow - remove reload, sync auth state reactively
This commit is contained in:
@@ -405,6 +405,13 @@ function AuthWrapper() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
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) {
|
if (window.WNW_CONFIG?.standaloneMode) {
|
||||||
fetch(window.WNW_CONFIG.restUrl + '/auth/check', {
|
fetch(window.WNW_CONFIG.restUrl + '/auth/check', {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
@@ -414,12 +421,13 @@ function AuthWrapper() {
|
|||||||
setIsAuthenticated(data.authenticated);
|
setIsAuthenticated(data.authenticated);
|
||||||
if (data.authenticated && data.user) {
|
if (data.authenticated && data.user) {
|
||||||
window.WNW_CONFIG.currentUser = data.user;
|
window.WNW_CONFIG.currentUser = data.user;
|
||||||
|
window.WNW_CONFIG.isAuthenticated = true;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => setIsAuthenticated(false))
|
.catch(() => setIsAuthenticated(false))
|
||||||
.finally(() => setIsChecking(false));
|
.finally(() => setIsChecking(false));
|
||||||
}
|
}
|
||||||
}, []);
|
}, [location.pathname, isAuthenticated]);
|
||||||
|
|
||||||
if (isChecking) {
|
if (isChecking) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -37,11 +37,8 @@ export function Login() {
|
|||||||
window.WNW_CONFIG.currentUser = data.user;
|
window.WNW_CONFIG.currentUser = data.user;
|
||||||
window.WNW_CONFIG.nonce = data.nonce;
|
window.WNW_CONFIG.nonce = data.nonce;
|
||||||
|
|
||||||
// Redirect to dashboard
|
// Redirect to dashboard (no reload needed, auth state is updated)
|
||||||
navigate('/dashboard');
|
navigate('/dashboard');
|
||||||
|
|
||||||
// Reload to ensure all auth state is fresh
|
|
||||||
window.location.reload();
|
|
||||||
} else {
|
} else {
|
||||||
setError(data.message || __('Invalid username or password'));
|
setError(data.message || __('Invalid username or password'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ $js_url .= '?ver=' . $version;
|
|||||||
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
||||||
</head>
|
</head>
|
||||||
<body class="woonoow-standalone">
|
<body class="woonoow-standalone">
|
||||||
<div id="woonoow-admin-root"></div>
|
<div id="woonoow-admin-app"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Minimal config - no WordPress bloat
|
// Minimal config - no WordPress bloat
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class StandaloneAdmin {
|
|||||||
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
||||||
</head>
|
</head>
|
||||||
<body class="woonoow-standalone">
|
<body class="woonoow-standalone">
|
||||||
<div id="woonoow-admin-root"></div>
|
<div id="woonoow-admin-app"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Minimal config - no WordPress bloat
|
// Minimal config - no WordPress bloat
|
||||||
|
|||||||
Reference in New Issue
Block a user